I am attempting to create a part that when touched gives players points, which it does, but gives them more than intended and even with a debounce is very glitchy. Also I am trying to make it so everyone who touches it gets only a single coin and win, but the debounce for the first player to touch doesn't allow this. This is what I have so far.
local brick = script.Parent
local buttonPressed = false
function onTouched(hit)
if not buttonPressed then
local buttonPressed = true
if hit.Parent:FindFirstChild("Humanoid")~=nil and game.Players:GetPlayerFromCharacter(hit.Parent)~=nil then
local player=game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Character then
local stat = player:FindFirstChild("leaderstats")
if stat then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-40, 1.5, 64)
wait(10)
buttonPressed = true
end
end
end
end
end
brick.Touched:connect(onTouched)

6 comments
The brick no longer does anything on touched. Doesn't give anything in output either.
@Draebrewop Is the script running?
Yes, inside a part.
@DanzLua Nevermind, it was my bad. I accidentally wrote a part of the script wrong.
However, for some reason it takes a around 5 seconds to give the points as well as teleport the player to the position, which happens even if I change the wait time?
@Draebrewop I don't see a reason for that to happen