Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i find the player for this script that teleports the player?

So i made this script for a GUI and now the script is inside a Part / Union in Workspace.

How can i find the Player and make it a variable?

game > Workspace > Teleporter > Script

plr = HOW TO DEFINE THE PLR?
Spot = game.Workspace.HangOutSpawn.Position

script.Parent.Touched:connect(function()
		plr.PlayerGui.Load.Frame.Visible = true
		wait(3)
		plr.Character:FindFirstChild("Torso").CFrame = CFrame.new(Spot)
		plr.PlayerGui.Load.Frame.Visible = false
end)

Turns out there is an error in line 5 as well if you could help me with that as well.

3 comments

0

Which player? The player whose Character touched script.Parent?

0

I think I've seen you ask questions similar to this. Are you sure you can't figure this out?

0

We need more info....

1 answer

✓ Accepted answer
local Spot = game.Workspace.HangOutSpawn.Position --Use locals ya fool!

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        	player .PlayerGui.Load.Frame.Visible = true
      		wait(3)
        	hit.Parent:FindFirstChild("Torso").CFrame = CFrame.new(Spot)
        	player .PlayerGui.Load.Frame.Visible = false
end)

game.Players:GetPlayerFromCharacter is what I used. It's the only efficient way of doing this, that I know of. Make sure you use locals, as they look a LOT nicer and are a lot easier to read. This is a guess as to what you are wanting help with. I have no clue what you needed help with, as you worded your question poorly.

If this helped you, please accept my answer. If this was the incorrect solution, or an error appeared with the script, then please comment below and tell me what the issue was.

This discussion is preserved as it was. New answers, comments, and votes are closed.