Teleporting Script Based on Leaderstats

So, I’m working on a team-based obby, and some of the teleporters to different obbies required a certain amount of wins. However, whenever I have tried testing them, say I have less than the required amount of wins, it still teleports me to the obby. I’m unsure if it is because of something I’m missing, or I am writing the script completely wrong. Here is the script below:

local Pad = game.Workspace.TwoPlayerObbies.Level5:FindFirstChild("Level5Pad")
local Teleporter = script.Parent
local requiredWins = 5 

Teleporter.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local winsValue = player:FindFirstChild("Wins")
        if winsValue and winsValue.Value >= requiredWins then
            local humanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
            if humanoidRootPart then
                humanoidRootPart.CFrame = Pad.CFrame + Vector3.new(0, 5, 0)
            end
        else
            print("Player does not have enough wins to teleport.")
        end
    end
end)

If there’s something I’m missing from this script, or if it is completely incorrect based on what I’m trying to use it for, please let me know!

1 Like

I believe you are trying to find the leaderstats value, so instead the script should be

local winsValue = player.leaderstats:FindFirstChild("Wins")

I added this into the script, but it for some reason still teleports me even after I change my amount of wins.

if players is still being teleported even when they dont have enough wins, the issue could be that the Wins value wasnt set up correctly, or the requiredWins value not being set to the correct value…

Teleporter.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local winsValue = player:FindFirstChild("Wins")
        if winsValue then
            print("Player wins:", winsValue.Value)
            print("Required wins:", requiredWins)
            if winsValue.Value >= requiredWins then
                local humanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
                if humanoidRootPart then
                    humanoidRootPart.CFrame = Pad.CFrame + Vector3.new(0, 5, 0)
                end
            else
                print("player does not have enough wins to teleport.")
            end
        else
            print("player does not have a Wins value.")
        end
    end
end)
2 Likes

Just tested this in-game and it works now. Tysm!

No problem, mark the post as the solution if it did actually help.