Kill for cash only local/client?

Hi!

So I’m making a western shooter and I’m making a system where you can buy items buy defeating other players.

This is the screen of the player defeating a different player.

Here is the other players screen that got defeated

On the defeated players screen the cash goes up, but not on the other player.

This is the script for the kill for cash system

game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new(“Folder”,player)
folder.Name = “leaderstats”
local currency1 = Instance.new(“IntValue”,folder)
currency1.Name = “cash”

player.CharacterAdded:connect(function(character)
character:WaitForChild(“Humanoid”).Died:connect(function()
local tag = character.Humanoid:FindFirstChild(“creator”)
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 100 --This is the reward after the player died.
end
end
end)
end)
end)

Is there a problem with this? If so, please help me!

You need to fire a remote event that adds the cash.

Ok. I’m new to scripting and i followed a tutorial so can you please explain how i can fire a remote event?

Watch this:

Hey there.
So your script right here is only local. For the cash to be visible to everyone else, or even save afterwards, you need to fire a RemoteEvent. They are practically designed to provide one way messages from the server to the client, or vice versa. Thus, include this in your local code after inserting a remote event named “FireCash” in your replicated storage. Remove the cash being added in your local script and add this statement after the function instead:

  game.ReplicatedStorage.FireCash:FireServer()

Once that’s taken care of, insert a new script in ServerScriptService, and execute this code:

game.ReplicatedStorage.FireCash.OnServerEvent:Connect(function(player)
     local cash = player:WaitForChild("leaderstats").Cash --or any currency name
     cash.Value = cash.Value + 100 --the reward you're adding
end)

I believe this code will work for you. If you want to learn more about remote events I suggest looking at the post above this.

2 Likes