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.
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.
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)
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)
I donât know why it doesnât work. I tried it and it worked.
Is there any errors?
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?
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)
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!
Okay thank you, this is in serverscriptservice?