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

[Solved] How to Teleport the Player when they click a part?

Asked by 5 years ago
Edited 5 years ago

So I have a game rn. And I have a lobby'ish place and I want it so that if the player clicks the block, then it'll teleport the player to a new part of the map. (Oh and I don't even know if the instance.new code is working.)

local firstSpawnFolder = game.workspace.FirstSpawnFolder
local clickForSpawnPart = firstSpawnFolder.ClickForSpawnPart
local clickDetector = clickForSpawnPart.ClickDetector
clickDetector.MouseClick:Connect(function(hit)
SamuraiSpawn = Instance.new("SpawnLocation",game.workspace)
SpawnLocation.Position = (237.4,2.1,-176.5)
SpawnLocation.Orientation = (0,110,0)
game.workspace.Players.LocalPlayer("Humanoid").Position = Vector3.new(237.4,2.1,-176.5)

end)
0
Ok so this pops up in the output when I click the part with @Kymaraaa 's script - Workspace.FirstSpawnFolder.ClickForSpawnPart.Script:8: attempt to index field 'LocalPlayer' (a nil value) Dudez2Good4u 20 — 5y

1 answer

Log in to vote
0
Answered by
Kymaraaa 116
5 years ago
Edited 5 years ago

First of all, you don't need to create a SpawnLocation as this is client side. and spawning is done via the server. Even if this code was on the server and working, it would redundant to make a spawn location each time.

local FirstSpawnFolder = game.workspace:FindFirstChild("FirstSpawnFolder")
local ClickDetector = FirstSpawnFolder:WaitForChild("ClickForSpawnPart"):WaitForChild("ClickDetector")
ClickDetector.MouseClick:Connect(function()
    game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(237.4, 2.1, -176.5)
end)

When teleporting a Character, you'll want to change their HRP's CFrame or else it will kill them.

The code above should work.

0
Your explanation makes no sense. DeceptiveCaster 3761 — 5y
0
Humanoids do not have CFrames nor do they have Positions. DeceptiveCaster 3761 — 5y
Ad

Answer this question