Reward to complete the obby

Problem I am facing
I am making an obby and there is a part on the end which gives the player in game currency which can be used to buy different things. I just want a script which lets the player get the currency(gems) only once. And when one player touches it all the other players in the server reset and go back to the main spawn. The gems are stored in leaderstats and 1k are given on finishing the obby. Please write a script for it if required and also add comments so I can edit it in the future if required.

Too lazy to give an explanation but I believe this is what you want?

local Part = script.Parent
local Winner = false

Part.Touched:Connect(function(Hit) --This will fire when a part touches another object
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
   
    if player and not Winner then --We're checking if the part that we touched is equal to a valid Player by getting the Character's Model, and if there's not already a winner
        Winner = true
        Player.leaderstats.Gems.Value += 1000

        for _, Player in pairs(game.Players:GetPlayers()) do  --Looping through all the Players to teleport them
            local Character = Player.Character

            if Character then
                Character.HumanoidRootPart.CFrame = CFrame.new(workspace.MainSpawn.Position + Vector3.new(math.random(-10, 10), 0, math.random(-10, 10))) --Teleporting all the players to a specific point
            end
        end
    end
end
1 Like