Squid game piggy bank

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.

1 Like

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?

1 Like

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.

1 Like

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

1 Like

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

1 Like

@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)
1 Like

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)
1 Like

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

1 Like

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.

1 Like

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…

1 Like

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)
1 Like

FireServer can only be called from the client