When I kill a zombie It gives cash but I cannot spend it!

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!

Yea a your giving your self the cash on the client and not on the server. You get the point? right?

Yes, but how can I fix that problem?

1 word: remote events. Use them so that the client sends a msg to the server to add a specific amount of cash.

2 Likes

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.

game['ReplicatedStorage'].ZombieKilled.OnServerEvent:Connect(function(player,cash)
      Leaderstats.Value += cash
end)

I think instead of using a string at the cash variable a number would be better :slight_smile: . cuz u cant add strings.

1 Like

It’s implied that the cash value is a number.

You would replace ‘cash amount here’ with a number.

I mean really

yea yea ik

1 Like

Where should I add those scripts to. I think I have to change

game['ReplicatedStorage'].ZombieKilled.OnServerEvent:Connect(function(player,cash)
      Leaderstats.Value += cash
end)

To

game.ReplicatedStorage.ZombieKilled.OnServerEvent:Connect(function(player,cash)
      Leaderstats.Value += cash
end)

This goes into the script you already have

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.

game.ReplicatedStorage.ZombieKilled.OnServerEvent:Connect(function(player,cash)
      Leaderstats.Value += cash
end)

An exploiter can just fire the event over and over and get millions of cash.

They’re just asking how to let the server know if they have cash so they can buy things in their game.

I’m not making their whole game and hacker-proofing it for them.

Edit: This is off-topic anyhow, why does this matter? What does a totally separate issue have to do with “This button doesn’t work”?

1 Like

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.

1 Like

[Fire Server Can only be called from the client]
Do you know how to fix this issue? I tried local script but it does not work