Squid game piggy bank

Do, you have better anti exploit? Because in some way the clianr would have to talk to the server to find our when the player died. And this is the best I know of.

1 Like

I’d try to stay away from StarterCharacterScripts for things like this. Exploiters can delete the scripts in their character (and it’ll replicate), making it so they can entirely disable this.

Did the original script not work? I’d be happy to solve any issues it ran into.

1 Like

The scripts that you sent?

extraaaa

Yeah, did it not work? If there are problems with it, feel free to post them and I’ll try to solve them for you

Okay I will try your scripts again

I have an idea. First put a normal script into the serverscriptservice.
Then place this code:

local IntValue = game.ReplicatedStorage:WaitForChild("PiggyBank")

game.Players.PlayerAdded:Connect(function(player)
	local recentlyDied = Instance.new("BoolValue", player)
	recentlyDied.Value = false
	local character = player.Character or player.CharacterAdded:Wait()
	local hum = character:WaitForChild("Humanoid")
	hum.Died:Connect(function()
		if recentlyDied.Value == false then
			recentlyDied.Value = true
			IntValue.Value += 147
		end
	end)
end)

1 Like

Yours doesn’t work and it doesn’t display any error messages, I don’t know what is wrong with it

Okay I will try this script, thank you

This one also doesnt work

Just to be sure you know what I’m looking for. When somebody dies +147 cash is placed into the piggy bank. And if somebody touches the piggy bank then they will get 147 cash

Hm, it’s possible that your player loaded in before studio added the event (happens a bit with studio). Try this:

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

function PlayerAdded(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

Players.PlayerAdded:Connect(PlayerAdded)

for i,Plr in pairs(Players:GetPlayers()) do
	PlayerAdded(Plr)
end

I noticed you also wanted it to give the person who touched the bank all the money, so I went ahead and did that too:

local Players = game:GetService("Players")
local PartToTouch = workspace.PiggyBank -- Change this
local Cash = game:GetService("ReplicatedStorage").Cash -- The IntValue
local debounce = false

PartToTouch.Touched:Connect(function(hit)
	if debounce then return end
	debounce = true
	local Char = hit:FindFirstAncestorOfClass("Model")
	local Plr = Char and Players:GetPlayerFromCharacter(Char)
	if Plr and (Cash.Value > 0) then
		Plr.leaderstats.Cash.Value += Cash.Value
		Cash.Value = 0
	end
	-- If you want a delay between touches, you can add a task.wait(time) here
	debounce = false
end)

1 Like

I don’t know why it doesn’t work. I tried it and it worked.
Is there any errors?

1 Like

Can you send me a gif?
I want to see how it will turn out

–Leaderstats

function onPlayerEntered(newPlayer)

	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 0

	cash.Parent = stats
	stats.Parent = newPlayer
	
end
game.Players.ChildAdded:connect(onPlayerEntered)

--There is an intvalue called PiggyBank
--RemoteEvent called DeathEvent

--Script I tried
local Players = game:GetService("Players")
local Cash = game.ReplicatedStorage.PiggyBank -- Set this to your cash value

function PlayerAdded(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Hum = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
		Hum.Died:Connect(function()
			Cash.Value += 147
		end)
	end)
end

Players.PlayerAdded:Connect(PlayerAdded)

for i,Plr in pairs(Players:GetPlayers()) do
	PlayerAdded(Plr)
end

You’re gonna want to make leaderstats a folder, otherwise it won’t show in the leaderboard.

Other than that, what isn’t working with it?

1 Like

1 Like

Okay so then how do I get the intvalue sent to a part and when you touch a part then you get the money

I don’t get the error messages

Try adding this to the part that gives you money. This is a normal script

local parToTouch = script.Parent
local debounce = false
local intVal = game.ReplicatedStorage:WaitForChild("PiggyBank")

parToTouch.Touched:Connect(function(hit)
	if hit ~= nil then
		if hit.Parent:FindFirstChildOfClass("Humanoid") then
			if game.Players:FindFirstChild(hit.Parent.Name) then
				if debounce == false then
					debounce = true
					local player = game.Players:GetPlayerFromCharacter(hit.Parent)
					local cash = player:WaitForChild("Cash")
					cash.Value += intVal.Value
					wait(3)
					debounce = false
				end
			end
		end
	end
end)

1 Like

I found the issue, sometimes the character spawned before the event was connected. Here’s the full, new script:

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

function CharacterAdded(Character,Player)
	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

function PlayerAdded(Player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"

	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = stats

	stats.Parent = Player

	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	CharacterAdded(Character)
	
	Player.CharacterAdded:Connect(function(Character)
		CharacterAdded(Character,Player)
	end)
end

local debounce = false

PartToTouch.Touched:Connect(function(hit)
	if debounce then return end
	debounce = true
	local Char = hit:FindFirstAncestorOfClass("Model")
	local Plr = Char and Players:GetPlayerFromCharacter(Char)
	if Plr and (Cash.Value > 0) then
		Plr.leaderstats.Cash.Value += Cash.Value
		Cash.Value = 0
	end
	-- If you want a delay between touches, you can add a task.wait(time) here
	debounce = false
end)

Players.PlayerAdded:Connect(PlayerAdded)

for i,Plr in pairs(Players:GetPlayers()) do
	PlayerAdded(Plr)
end

This handles both adding cash on death and giving the player who touched the object cash. Be warned, the touched event doesn’t compensate for exploiters teleporting!

1 Like

Okay thank you, this is in serverscriptservice?