Squid game piggy bank

Hello, I am trying to make a piggy bank like the one holding all the cash in squid game. I want to make it so if somebody dies it will add +147 cash to the piggy bank. No visuals are needed I just need it to be able to give all the cash from every death to the player when they touch the piggy bank

Just put an IntValue into ReplicatedStorage and then with a server script add 147 each time. You can do this by doing 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)
     IntValue.Value += 147
end)

(server script)

1 Like

Okay I will try this method out, thank you

1 Like

Would I just need to insert a localscript into my mesh with a touch event and fire the event?

So, add a local script into StarterPlayerScripts with this code;

local RE = game.ReplicatedStorage.DeathEvent -- gets the remote event

local char = script.Parent.Parent.Character or script.Parent.Parent.ChararterAdded: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

Okay, thanks so much! Is there anything else important I should know?

Woops… I put some code in the wrong place in the local script, i fixed it now. Grab that code instead.

1 Like

Oh okay, is that all by the way?

Should be. If it doesn’t work then send me the error. There might be some spelling errors scince I wrote it all on mobile lol.

1 Like

Oh wow you are on mobile and you can do all this, I’ll let you know right now

Players.supreme_comrade.PlayerScripts.LocalScript:6: attempt to index nil with 'Died

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() --fires to the server
end)
2 Likes

Oh I see, thank you for the info

Okay, can you add a print stament in the local script right before the function fires.

print(script.Parent.Parent.Name)

Then tell me what it prints out.

1 Like

Okay I will do that right now

extraaaa

Wait should I first add a touch function to my piggy bank mesh?

When the player dies, that should do all the work that you need. Is your piggy bank what they’ll collect from? If so then yes.

1 Like

PLEASE DON’T DO THIS. This is very vulnerable to exploiters. Exploiters could send the remote as much as they want and increase the amount of cash to the millions.

Instead, do this in a server script:

local Players = game:GetService("Players")
local Cash = workspace.Cash -- Set this to your cash value

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Hum = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
		Hum.Died:Connect(function()
			Cash.Value += 147
			-- If you want to kick the player after they die, try this:
			Player:Kick("You died!")
		end)
	end)
end)
1 Like

Oh, and if you havn’t yet try @XObbyCreatorX s code, that might fix it.

1 Like

Character is not a valid member of PlayerScripts “Players.supreme_comrade.PlayerScripts”

And it also prints “Money Pig”