My script is supposed to detect If the player is touching a part, then give them a win and some points. If the player jumps on the win button, however, they can get up to 5 wins. Is there a way to fix this?
Script:
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local checkpoint = script.Parent
function onTouched(hit)
if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
player:LoadCharacter()
player:WaitForChild("leaderstats").Wins.Value = player:WaitForChild("leaderstats").Wins.Value + 1
player:WaitForChild("leaderstats").Points.Value = player:WaitForChild("leaderstats").Points.Value + math.random(20,30)
local checkpointData = ServerStorage:FindFirstChild("CheckpointData")
if not checkpointData then
checkpointData = Instance.new("Folder")
checkpointData.Name = "CheckpointData"
checkpointData.Parent = ServerStorage
end
local userIdString = tostring(player.UserId)
local checkpointValue = checkpointData:FindFirstChild(userIdString)
if not checkpointValue then
checkpointValue = Instance.new("ObjectValue")
checkpointValue.Name = userIdString
checkpointValue.Parent = checkpointData
player.CharacterAdded:connect(function(character)
wait()
local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value
character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4)))
end)
end
checkpointValue.Value = workspace.Start.SpawnLocation
end
wait(1)
end
checkpoint.Touched:Connect(onTouched)

5 comments
aaaa, i over complicated it thx for the reply.
Would I put my script before the wait(1)
Yeah, you would.
Wow, this worked like a charm! Tysm!
Yw. :>