Teleport a player to another part

Hi, I’m currently making a simple sword fightning game, and I’m not really of an advanced scripter and I’m learning, so I keep the game simple. Now to my problem. The game works so that when you join the game there is a GUI with a play button and when you click the play button, you spawn on a platform with a table with a sword on it. And it’s intended so that when you click on the sword you get it and is moved to an arena where all the players fight. But i don’t know how to make it so when you click it you get moved there. I have searched on the internet, and I’m also not so good at scripting, so it’s hard to know how to make it. If someone has a solution please reply here down. Thank you

My script:

local Tool = script.Parent.Parent
local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(Player)
	Tool:Clone().Parent = Player.Character 
	
	local character = Player.Parent:WaitForChild("Character")
	
	character.Position = Vector3.new(-114.008, 1.5, 26.29)
			
			
end)

script.Parent.CanTouch = false --Just to make the sword equipable only by clicking it, not touching it
	

Have a nice day!

1 Like

Thats not how you get the character

Use MoveTo if you want to move the Character, PivotTo, SetPrimaryPartCFrame for the same thing, or move the HumanoidRootPart

MoveTo Supports Vector3
PivotTo Supports CFrame
SetPrimaryPartCFrame is Deprecated
Move HumanoidRootPart with CFrame or Vector3

ClickDetector.MouseClick:Connect(function(Player)
	Tool:Clone().Parent = Player.Character 
	
	Player.Character:MoveTo(Vector3.new(-114.008, 1.5, 26.29))						
end)


1 Like

First of all, character should be Player.Character and then use :SetPrimaryPartCFrame or :PivotTo method, both take CFrame as an argument.

Here ya go. Hope this helps.

ClickDetector.MouseClick:Connect(function(player)
    Tool:Clone().Parent = Player.Character
    local char = player.Character		
    local location = Vector3.new(-114.008, 1.5, 26.29)			
    char:MoveTo(location)
end)

Thank you! Now it works as I want it :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.