#Part teleportation Help

85 messages · Page 1 of 1 (latest)

slender moat
#

So am trying to make a script that when you trigger proximity prompt it teleports you to a part but it doesnt teleport me so can anyone help me fix it?

-- get the part in the workspace to teleport the player to
local teleportPart = workspace.TeleportPart

-- function to handle proximity prompt triggered events
local function onPromptTriggered(prompt, player)
-- get the player's leaderstats
local leaderstats = player:FindFirstChild("leaderstats")

-- check if the player's level is equal to 1
if leaderstats and leaderstats.Level.Value == 1 then
    -- teleport the player to the teleportPart
    player.Character:SetPrimaryPartCFrame(teleportPart.CFrame)
end

end

-- find the proximity prompt in the workspace
local prompt = workspace:FindFirstChild("ProximityTeleport")

-- connect the prompt triggered event to the onPromptTriggered function
prompt.Triggered:Connect(onPromptTriggered)

wise sun
slender moat
#

Yeah

#

And it doesnt work

wise sun
#

Ofc it doesn't

slender moat
wise sun
#

Just change the player's character position to the part position

slender moat
#

I did

desert mauveBOT
#

studio** You are now Level 3! **studio

slender moat
#

And it still does not work

#

I even tried tutorials

wise sun
#

Show script shy

slender moat
#

let me see my own version

#

local parent = script.Parent
local Level1tp = game.Workspace.Maps["Backrooms - Level 1"].Spwan
local lds = game.Players.LocalPlayer.leaderstats
local player = game.Players.LocalPlayer

script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
if lds.Level.Value == 1 then
local CurrentlyTeleporting = Player:FindFirstChild("CurrentlyTeleporting")
if not CurrentlyTeleporting then return end

    if not CurrentlyTeleporting.Value then
            CurrentlyTeleporting.Value = true
            Player.Character.HumanoidRootPart.CFrame = Level1tp.CFrame + Vector3.new(0,5,0)
            wait(3)
            CurrentlyTeleporting = false
        end
    end
end

end)

#

That one as well does not work

#

does not print any errors

slender moat
#

local

#

It has to be local

wise sun
#

Why are you trying to get the player from character if its local agony

slender moat
#

You cant mention the hiy

#

hit

#

I just need fixes for the code

wise sun
#

Just do in normal script

#

It works too

slender moat
#

How

#

If I have game.Players.LocalPlayer

wise sun
#

When hit it checks the player

slender moat
#

I also need it for leaderstats

#

not only for hit

wise sun
#

Just put it inside the function .touched

slender moat
#

Ok

wise sun
#

I think

#

I haven't script for 3 months and only learned for 1 month im still beigner shy

slender moat
#

I cant mention .LocalPlayer in a normal script

minor lake
#

local function onPromptTriggered(player)

#

thats how you do it

slender moat
#

I just need a full round up of it

#

not shorts to it

#

I really need to get tthis fixed

minor lake
#

I'll send the full script of what it would look like

slender moat
#

ok

minor lake
#

REGULAR SCRIPT, NOT LOCAL

local parent = script.Parent
local Level1tp = game.Workspace.Maps["Backrooms - Level 1"].Spwan

script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local lds = Player.leaderstats
if Player then
if lds.Level.Value == 1 then
local CurrentlyTeleporting = Player:FindFirstChild("CurrentlyTeleporting")
if not CurrentlyTeleporting then return end

    if not CurrentlyTeleporting.Value then
            CurrentlyTeleporting.Value = true
            Player.Character.HumanoidRootPart.CFrame = Level1tp.CFrame + Vector3.new(0,5,0)
            wait(3)
            CurrentlyTeleporting = false
        end
    end
end

end)

#

there maybe try that

slender moat
#

ok

#

all of it immediately errored

minor lake
#

get rid of the "edited" and [9:10 pm] thinig

#

cause that will mess it up

slender moat
#

Oh

minor lake
#

Im also checking for other errors

slender moat
#

Attempted to index nil leaderstats

#

Due to leaderstats is created inside the local player

#

thats why I did it in a local script

slender moat
wise sun
slender moat
#

We alrwady got people thanks though

wise sun
#

ok

minor lake
#

you have to do it inside a regular server script, this is how:

first make a script in ServerScriptService

then write this code:

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

local Level = Instance.new("IntValue",leaderstats)
Level.Name = "Level"
Level.Value = 1

local CurrentlyTeleporting = Instance.new("BoolValue", player)
CurrentlyTeleporting.Name = "CurrentlyTeleporting"
CurrentlyTeleporting.Value = false
end)

slender moat
#

this is my leaderstats Code

minor lake
#

yes good

slender moat
#

I dont need the currently teleporting

#

I deleted it

minor lake
#

ohh okay

#

yeah it looks good

slender moat
#

what it looks right now

#

the thing is

#

It cant index leaderstats due to it being in the local player himself

minor lake
#

"Player.leaderstats" not "game.Players.leaderstats "

#

or it wont work

slender moat
#

k

minor lake
#

other than that it looks good to me

#

so I think it will work now

slender moat
#

FINALLY IT WORKS

desert mauveBOT
#

studio** You are now Level 4! **studio

minor lake
#

YAY!

slender moat
#

Thank you so much man

#

I have been trying to get it to work for weeks now

minor lake
#

Youre welcome 🙂

#

lol that was me when I started

#

scripting just takes a lot of learning and practice but before you know it you can script like anything

slender moat
#

I sometimes get scripts to work

#

and some dont