Preparation
Click here to add the model: https://www.roblox.com/library/7777479010/Maps-TycoonÂ
Use toolbox, search and find zombie. Chose “Drooling Zombie” model and add it into the game.
Workspace
ReplicatedStorage
Gold==>Script
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent.Humanoid.Health > 0 then
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + script.Parent.Gold.Value
script.Parent:Remove()
end
end
end)
ServerScriptService, serverstorage
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ammoEvent = ReplicatedStorage:WaitForChild('AmmoEvent')
game.ReplicatedStorage.HealthEvent.OnServerEvent:Connect(function(player)
if player.leaderstats.Gold.Value >=10 then
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 10
player.Character.Humanoid.Health = player.Character.Humanoid.Health + 30
end
end)
game.ReplicatedStorage.AmmoEvent.OnServerEvent:Connect(function(player)
if player.leaderstats.Gold.Value >=10 then
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value - 10
ammoEvent:FireClient(player)
end
end)
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Value = 0
Kills.Parent = leaderstats
local Death = Instance.new("IntValue")
Death.Name = "Death"
Death.Value = 0
Death.Parent = leaderstats
local gold = Instance.new("IntValue")
gold.Name = "Gold"
gold.Value = 0
gold.Parent = leaderstats
end
-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
Players.PlayerAdded:Connect(leaderboardSetup)
--Death Tracker
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild('Humanoid').Died:Connect(function()
player.leaderstats.Death.Value = player.leaderstats.Death.Value + 1
end)
end)
end)
local spawnWorkspace = game.Workspace.SpawnedZombie
local gameStatus = game.ReplicatedStorage.Values:WaitForChild("gameInProgress")
local zombieRemaining = game.ReplicatedStorage.Values:WaitForChild("zombiesRemaining")
while true do
gameStatus = true
zombieRemaining = 6
if gameStatus == true then --game.ReplicatedStorage.Values.gameInProgress.Value == true then
if zombieRemaining > 0 then
local NPC = game.ReplicatedStorage["Drooling Zombie"]:Clone()
local randomSpawn = game.Workspace.Map.SpawnPoints:GetChildren()
NPC.Parent = game.Workspace.SpawnedZombie --script.Parent
NPC.HumanoidRootPart.CFrame = randomSpawn[math.random(1,#randomSpawn)].CFrame
zombieRemaining = zombieRemaining - 1
end
end
wait(5)
end
local bullet = script.Parent
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
game:GetService("Debris"):AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
local function playerCheck(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
humanoid:TakeDamage(30)
UntagHumanoid(humanoid)
TagHumanoid(humanoid,game.Players:FindFirstChild(bullet.Attacker.Value))
end
end
bullet.Touched:Connect(playerCheck)
--Object and Sound Variables
local gun =script.Parent
local gunShot = gun.Handle['Gun Shot']
local empty_sound = gun.Handle.clip_empty
local reload_sound = gun.Handle["Gun Reload"]
--part4
local player = game.Players.LocalPlayer
local clipsize = gun:WaitForChild('Ammo').Value
local ammo = gun:WaitForChild('Ammo')
-- User Input Service Setup
local userInput = game:GetService('UserInputService')
-- Mouse Icon
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = 'rbxassetid://2302147960'
-- RemoteEvent
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
--part 5--
local ammoEvent = ReplicatedStorage:WaitForChild('AmmoEvent')
--update Ammo Function -- part5
local function update_ammo()
player.PlayerGui.ScreenGui.Ammo.Text = "Ammo : "..tostring(ammo.Value).." / "..gun.MaxAmmo.Value
end
--Check if mouse clicked
gun.Equipped:Connect(function(mouse)
--part4
player.PlayerGui.ScreenGui.Ammo.Visible = true
update_ammo() --part5-
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p) -- part4 modification
gunShot:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
else
empty_sound:Play()
end
end)
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
end)
-- Unequipped Gun -- part4
gun.Unequipped:Connect(function()
--part4
player.PlayerGui.ScreenGui.Ammo.Visible = false
end)
-- Check if the keyboar R is pressed
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R then
if gun.Ammo.Value < clipsize and gun.MaxAmmo.Value > 0 then
reload_sound:Play()
reload_sound.Ended:Wait()
--part4
if gun.MaxAmmo.Value - (clipsize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipsize - gun.Ammo.Value)
gun.Ammo.Value = clipsize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
update_ammo()
end
--gun.Ammo.Value = 10
end
end
end
end
end)
--[[ UPdate AmmoGUI -- part4
ammo.Changed:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Text = "Ammo : "..tostring(ammo.Value).." / "..gun.MaxAmmo.Value
end) ]]
ammo.Changed:Connect(update_ammo)
ammoEvent.OnClientEvent:Connect(function()
gun.MaxAmmo.Value = gun.MaxAmmo.Value + 10
update_ammo()
end)
StarterGui
local ContextActionService = game:GetService("ContextActionService")
local plr = game.Players.LocalPlayer
local function perspectiveToggle(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.End then
if plr.CameraMode == Enum.CameraMode.Classic then
plr.CameraMode = Enum.CameraMode.LockFirstPerson
elseif plr.CameraMode == Enum.CameraMode.LockFirstPerson then
plr.CameraMode = Enum.CameraMode.Classic
plr.CameraMaxZoomDistance = 25
plr.CameraMinZoomDistance = 25
plr.CameraMaxZoomDistance = 128
plr.CameraMinZoomDistance = .5
end
end
end
ContextActionService:BindAction("PerspectiveToggle",perspectiveToggle,true,Enum.KeyCode.C)
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.HealthEvent:FireServer()
end)
--part4
local player = game.Players.LocalPlayer
local health_label = script.Parent
while wait() do
local percent = player.Character.Humanoid.Health / player.Character.Humanoid.MaxHealth
if percent < 0.1 then
health_label.BackgroundColor3 = Color3.new(255,0,0)
end
if percent >= 0.1 and percent <= 0.75 then
health_label.BackgroundColor3 = Color3.new(100,255,0)
end
if percent > 0.75 then
health_label.BackgroundColor3 = Color3.new(0,255,0)
end
health_label.Size = UDim2.new(percent-0.2,0,0.8,0)
health_label.Text = math.floor(player.Character.Humanoid.Health)
end
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.AmmoEvent:FireServer()
end)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
player.PlayerGui.ShopUI.Frame.Visible = false
end)
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.HealthEvent:FireServer()
end)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
player.PlayerGui.ShopUI.Frame.Visible = true
end