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

Teleport script only works in studio and never in game, what am I doing wrong?

Asked by 6 years ago

I'm trying to make a script that teleports someone who clicks a button, but it never works in game it only works in studio. What did I do wrong?

function onClicked(playerWhoClicked)
    hum = game.Players.LocalPlayer.Character
    hum.Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position) 
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Is this in a local script or a server script? iSvenDerp 233 — 6y
0
It's a server script. onionStick 7 — 6y
1
Since you Used LocalPlayer for your "hum" Variable, you will need to try it in a local script since LocalPlayer is used in Local Scripts.. Im not sure if it will work, but see if it will iSvenDerp 233 — 6y
0
It doesn't work. Is the problem the LocalPlayer? I wasn't sure how else to find the player who clicked it. onionStick 7 — 6y
View all comments (3 more)
0
Look, I gtg so I cant really help you right now, but Local scripts do not work in Workspace, and I believe your problem is using Local Player, so you will need probably need to access the player another way, I will be back on tomorrow to see if you figured it out, then I can help then.. iSvenDerp 233 — 6y
0
Okay, I'll try and figure it out onionStick 7 — 6y
0
I edited my question. hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

[Edited] You should use the player value that is in the function.. Here is your script using it. Also, I edited some stuff that is unnecessary.

script.Parent.ClickDetector.MouseClick:connect(function(plr) --Plr is a short way to say player. It makes writing your scripts easier. 
    game.Workspace[plr.Name].Torso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position) --I am just saying, but you should use the head to make it R15 compatible. 
end)
0
That didn't work either. The two error messages were "attempt to call a nil value" and "Torso is not a valid member of Player" if that helps at all. onionStick 7 — 6y
0
The edited version worked! Thanks! onionStick 7 — 6y
Ad
Log in to vote
0
Answered by
0msh 333 Moderation Voter
6 years ago

Put this inside of the button script

local spawn = game.Workspace.TeleportLocation -- make a brick in the Workspace name 'TeleportLocation'.
player = script.Parent.Parent.Parent.Parent.Parent.Parent  -- if this script doesn't work, look at this line. Make sure the final Parent is Workspace.

function onClicked()
    player.Character.Torso.CFrame = CFrame.new(spawn.Position)
end

script.Parent.MouseButton1Down:connect(onClicked)

Accept answer and up vote if this works, thank!

0
It still isn't working, the error message is "Character is not a valid member of Workspace" if that helps. onionStick 7 — 6y

Answer this question