Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a teleporter depending on leaderstats?

Asked by 2 years ago

So I have this game with dimensions, How do I make it so if you have for instance 14 “points” in the leader stats, then you can be able to touch a specific part and teleport to a place?

(Basically, you can only teleport to this place by touching a part and it will only teleport you if you have for example 14 points in the leader stats), how do I make that?

2 answers

Log in to vote
0
Answered by 2 years ago

I think this will work:

Leaderboard script (ServerScriptService)

game:GetService("Players").PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player


    local points = Instance.new("IntValue")
    -- Name to what it's called
    points.Name = "Points"
    points.Parent = leaderstats
    points.Value =0
end)

Teleport script (Part)

-- Points needed to teleport:
local POINTS_NEEDED_TO_TELEPORT = 14

-- Name to the part you want to teleport to
local TeleportPart = workspace.Teleport

local function teleport(character, part)
    character.HumanoidRootPart.CFrame = part.CFrame + Vector3.new(0,5,0)
end
script.Parent.Touched:Connect(function(hit)
    local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
    if hum then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if player then
            local leaderstats = player:FindFirstChild("leaderstats")
            if leaderstats then
                local points = leaderstats:FindFirstChild("Points")
                if points then
                    if points.Value >= POINTS_NEEDED_TO_TELEPORT then
                         teleport(hit.Parent, TeleportPart)
                    end
                else
                    warn(tostring(player), "does not have points!")
                end
            else
                warn(tostring(player),"does not have leaderstats!")
            end
        end
    end
end)

Tell me if it doesn't work.

0
I'll try it and let you know, thank you so much! Ghostinee 27 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Here's the code, hope its helping you :)

Leaderstats script :

local plrs = game:GetService("Players")

plrs.PlayerAdded:Connect(function(p)

    local LS = Instance.new("Folder")
    LS.Name = "leaderstats"
    LS.Parent = p

    local Value = Instance.new("IntValue")
    -- Change the string to anything you desired
    Value.Name = "Value" 
    Value.Value = 0
    Value.Parent = LS
end)

Teleport script :

local plrs = game:GetService("Players")

-- Change the Value of the Variable to anything you desired
local valueneed = 1

-- Put the script into the part or change it to "workspace.(YOUR PART'S NAME)"
local tpPart = script.Parent

-- Change this to the "endPos" to Part's name
local endPos = workspace.endPos

function tp(char, pos)
    char:PivotTo(char:GetPivot() * pos.CFrame)
end

tpPart.Touched:Connect(function(h)
    local p
    local LSValue

    if h.Parent:IsA("Model") or h:FindFirstAncestorOfClass("Model") then

        if h.Parent:FindFirstChild("Humanoid") then
            p = plrs:GetPlayerFromCharacter(h.Parent)
            LSValue = p.leaderstats.Value 

            if LSValue.Value >= valueneed then
                tp(h.Parent, endPos)
            elseif LSValue.Value <= valueneed then
                print("The value is not enough")
            elseif p.leaderstats == nil then
                print("Leaderstats are not found!")
            end
        end
    end
end)

If not work, tell me.

0
... echobloxia 21 — 2y
0
I'll try it and let you know if it doesn't work, thank you so much!! Ghostinee 27 — 2y
0
btw echo, u can tell me if there's any copy of it GoldenKnightFly 0 — 2y

Answer this question