Hello. I am trying to make a very simple script. When a zombie dies, it should give you money, and then you can spend it on your tycoon (Zed Tycoon Kit)
Here is my problem:
The Script:
local Humanoid = script.Parent.Humanoid
local ui = game.StarterGui.Money
function all()
local tag = Humanoid:findFirstChild("creator")
local ui = game.StarterGui.Money
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:findFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 25
ui.Enabled = true
wait(6)
ui.Enabled = false
wait(0.1)
script:remove()
end
end
end
end
Humanoid.Died:connect(all)
Does anyone know how to fix this problem?
Thank you!
Add these to the localscript, and make a RemoteEvent called something like âZombieKilledâ in ReplicatedStorage or ReplicatedFirst.
local cash = 'cash amount here'
-- the amount of cash you want to add to the bank. Add this variable at the top
game['ReplicatedStorage'].ZombieKilled:FireServer(cash)
-- tells the game how much cash the player has, not just the player
Leaderstats should be changed in the server and not in a localscript, like something in Workspace or ServerScriptService.
I.E. Add a separate script to handle when the RemoteEvent fires to ServerScriptService. This tells THE GAME ITSELF that you have money. Essentially, you were only telling your own computer that you earned money, but the server/other players donât know you have the money.
local cash = 'cash amount here'
-- the amount of cash you want to add to the bank. Add this variable at the top
game['ReplicatedStorage'].ZombieKilled:FireServer(cash)
-- tells the game how much cash the player has, not just the player
This goes in ServerScriptService.
Whatever Leaderstats is, make your variable for that in this script.
It wouldâve been fine if you warned him about the possibilities of exploiters abusing these remoteevents but you didnât and therefore youâre teaching him bad-practice.
@GTX_3
You should be handling zombie kills on the server and adding to their cash via that way. That way you donât have to worry about remoteevents.