Okay so Basically I have made a teleporter that returns the player to the lobby and gives them cash, however, for some reason the debounce gets activated early and doesn't do the if loop, to combat this I added a wait before the debounce which works, however it will give the player a ton of cash, usually about 70 dollars, I know this is because parts of the body are activating the if statement before the debounce turns on I just don't know what to do.
Original code that skips the if statement and prints error:
local p = script.Parent
debounce = false
p.Touched:Connect(function(plr)
if plr.Parent.Name ~= "Stalker" then -- Checks to see if they are the killer in the game
if debounce == false then
debounce = true
plr.Parent.HumanoidRootPart.CFrame = game.Workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
wait()
local pp = plr.Parent.Name
local e = game.Players:FindFirstChild(pp)
print(pp, " found")
local ppp = e:FindFirstChild("leaderstats")
local cash = ppp:FindFirstChild("Cash")
cash.Value = cash.Value+10
print("Gave Cash to ", pp)
wait(2)
debounce = false
elseif debounce == true then print("Error")
end
end
end)
Altered code that gives random amounts of money:
local p = script.Parent
debounce = false
p.Touched:Connect(function(plr)
if plr.Parent.Name ~= "Stalker" then
if debounce == false then
wait()
debounce = true
plr.Parent.HumanoidRootPart.CFrame = game.Workspace.Lobby.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
wait()
local pp = plr.Parent.Name
local e = game.Players:FindFirstChild(pp)
print(pp, " found")
local ppp = e:FindFirstChild("leaderstats")
local cash = ppp:FindFirstChild("Cash")
cash.Value = cash.Value+10
print("Gave Cash to ", pp)
wait(2)
debounce = false
elseif debounce == true then print("Error")
end
end
end)

1 comment
Hey thanks for the help, I appreciate it, the change sort of fixed the issue but it turned out there was problems on my part with putting the teleporter vertically so it couldn't find the humanoid. Thanks for all the kind words!