This is way to complicated than it needs to be, you could easily just check if the plrs userid is the same with an if statement in the regular code.
Do I set the cash variable to my leaderstats or my piggy bank name?
How are you storing the money? Is it in an IntValue, or is it hanging out in a script? Does each player have their own cash amount?
MrBogo_YT gave me a script that stores it in an IntValue from replicatedstorage
Okay, so youâd probably want to set the Cash variable to that IntValue.
Okay, is that script a new script or do I replace something?
Iâm not sure what you mean by
Can you show me what you mean?
Also, this looks complicated but it handles players joining too
You probably just want to put it in a normal Script somewhere, preferably in ServerScriptService. It doesnât use script
anywhere, so itâs safe to go almost anywhere
The LocalScript and death event are no longer necessary (and they were insecure), so feel free to get rid of them
@MRBOGO_YT had a typo in his code. Fixed it
local RE = game.ReplicatedStorage.DeathEvent -- gets the remote event
local char = script.Parent.Parent.Character or script.Parent.Parent.CharacterAdded:Wait() --finds the character
local hum = char:FindFirstChild("Humanoid") -- finds the humanoid
hum.Died:Connect(function() --Runs when the player dies
RE:FireServer() --fires to the server
end)
Character is not a valid member of PlayerScripts âPlayers.supreme_comrade.PlayerScriptsâ
I have this error
Yeah that would mean I added and extra â.Parentâ lol.
local RE = game.ReplicatedStorage.DeathEvent -- gets the remote event
local char = script.Parent.Character or script.Parent.CharacterAdded:Wait() --finds the character
local hum = char:FindFirstChild("Humanoid") -- finds the humanoid
hum.Died:Connect(function() --Runs when the player dies
RE:FireServer(script.Parent.userId "Its either userId or UserId I forgot lol") --fires to the server
end)
Thank you but I already found that error
The error was probably for the print()
If you parented the local script to the starterplayerscripts, my code should work
Now in your server script, edit it to this;
local IntValue = game.ReplicatedStorage.PiggyBank --The name of the IntValue
local RE = game.ReplicatedStorage.DeathEvent -- An event to fire when a player dies
RE.OnServerEvent:Connect(function(plr, userId)
If plr.userId == userId then
IntValue.Value += 147
end
end)
Edit;
This is with anti exploit included. Meaning somebody canât up their money. But if someone else has some better anti exploit definatly use theirs, this is one that I tought myself and might not be ompletely unbreakable.
It is already there but it still does not work
Players.supreme_comrade.PlayerScripts.LocalScript:6: attempt to index nil with âDiedâ
This is a new error
local RE = game.ReplicatedStorage.DeathEvent -- gets the remote event
local char = script.Parent.Parent.Character or script.Parent.Parent.CharacterAdded:Wait() --finds the character
local hum = char:FindFirstChild("Humanoid") -- finds the humanoid
hum.Died:Connect(function() --Runs when the player dies
RE:FireServer() --fires to the server
end)
This wouldnât change anything, an exploiter could just add along its own UserIdâŚ
Also, why not change the local script to a normal script then parent in to the startercharacterscripts. Then put this code:
local RE = game.ReplicatedStorage:WaitForChild("DeathEvent") -- gets the remote event
local char = script.Parent
local hum = char:WaitForChild("Humanoid") -- finds the humanoid
hum.Died:Connect(function() --Runs when the player dies
RE:FireServer() --fires to the server
end)
FireServer can only be called from the client