Ive got this win brick which gives you a "Win" and 15 "Money" and it teleports you. It normally teleports you but there is a odd occasion where it doesn't teleport you. I really need help fixing this.
debounce = false
local PointsService = game:GetService("PointsService")
win = 1
money = 15
function onTouched(part)
if debounce == false then
debounce = true
local humanoid = part.Parent:findFirstChild("Humanoid")
if (humanoid~=nil) then
local thisplr = game.Players:findFirstChild(humanoid.Parent.Name)
print("3")
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Wins")
local score2 = stats:findFirstChild("Money")
local score3 = stats:findFirstChild("Level")
if (score~=nil) then
print("1")
score.Value = score.Value + win
print("2")
if (score2~=nil) then
score2.Value = score2.Value + money
local torso = part.Parent:findFirstChild("Torso")
torso.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,10,0)
if score.Value >= 5 and score.Value <= 15 then --Level 2
score3.Value = 2
elseif score.Value >= 16 and score.Value <= 30 then --Level 3
score3.Value = 3
elseif score.Value >= 31 and score.Value <= 50 then --Level 4
score3.Value = 4
elseif score.Value >= 51 and score.Value <= 80 then --Level 5
score3.Value = 5
else
wait(0.1)
end
local torso = part.Parent:findFirstChild("Torso")
local humanoid = part.Parent:findFirstChild("Humanoid")
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
if humanoid.Parent:FindFirstChild("Sword") then
humanoid.Parent.Sword:Destroy()
elseif thisplr.Backpack:FindFirstChild("Sword") then
thisplr.Backpack.Sword:Destroy()
elseif thisplr.Backpack:FindFirstChild("Spork") then
thisplr.Backpack.Spork:Destroy()
elseif humanoid.Parent:FindFirstChild("Spork") then
humanoid.Parent.Spork:Destroy()
else
wait(0.1)
end
PointsService:AwardPoints(thisplr.userId, 15)
wait(1)
debounce = false
end
end
end
end
end
elseif debounce == true then
wait(1)
end
end
script.Parent.Touched:connect(onTouched)
I have no idea what line it bugs up. There are no errors or anything and it really bugs me out. So my question is why does it not work sometimes?
