Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does .Touch on a part just keep repeating itself??

First It just keeps giving me the cash then I try using script.Disabled = true it still does not work

local AmountGiven = 15
script.Parent.Touched:Connect(function(PlayerPart)
	local CharName = PlayerPart.Parent.Name
	local Player = game.Players:FindFirstChild(CharName)
	local Cash = Player.leaderstats.Cash
	Cash.Value = Cash.Value + AmountGiven
	script.Disabled = true
	Player.Team = game.Teams["Non Playing"]
	PlayerPart.Parent.Humanoid.Health = 0
	script.Parent.Parent.Parent.Parent:Destroy()
end)

it says 15 for giving cash but it gives me 450 when I touch the object

2 answers

✓ Accepted answer

Simply add in a debounce. A debounce will prevent spam.

local AmountGiven = 15
local debounce = false

script.Parent.Touched:Connect(function(PlayerPart)
	if debounce == false then
		debounce = true
		local CharName = PlayerPart.Parent.Name
		local Player = game.Players:FindFirstChild(CharName)
		local Cash = Player.leaderstats.Cash
		Cash.Value = Cash.Value + AmountGiven

		Player.Team = game.Teams["Non Playing"]
		PlayerPart.Parent.Humanoid.Health = 0
		script.Parent.Parent.Parent.Parent:Destroy()
		wait(1)
		debounce = false
	end
end)

3 comments

0

That did not work for me still

0

I still have 450 Cash after reseting my cash and trying your script.

0

Oh wait its because I had 435 before yes it works

I HATE THAT IT JUMBLES UP THE STUPID CODE NONE CAN UNDERSTAND

2 comments

0

You use the blue Lua icon, check in edit mode, i edited your question ^^

0

K thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.