How can I move a player to a part?

Code :

local part = script.Parent

part.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

	if humanoidRootPart then
		local newCframe = game.Workspace.Areas.Area.CFrame
		humanoidRootPart.CFrame = newCframe
	end
end)

I don’t the code needs to be this complicated but I am new to scripting so I don’t exactly know, thank you!

That code looks like it should work. What is the problem? You check to see if there is an error in the Output view. That may help you solve the issue.

you can try something like

HRP.CFrame = CFrame.new(the x,y,z cframe of the part)

I don’t get teleported. charschars

I tried

local part = script.Parent

part.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	print("cool")

	if humanoidRootPart then
		local targetCFrame = game.Workspace.Areas.Area.CFrame
		humanoidRootPart.CFrame = targetCFrame
		print("wow")
	end
end)



none of the print statements print

Make sure the property CanTouch Is set to true. So the part can detect if something touched the part. And also make sure the part you are touching is the one you are defining in your script

local part = script.Parent
part.Touched:Connect(function(hit)
	local character = hit.Parent
    character:PivotTo(game.Workspace.Areas.Area)
end)

PivotTo better way to teleport player

Tried it. Doesn’t work. charssd

Yes, it is the same part and CanTouch and CanCollide are both true.

Is the script enabled? Did u get any errors. Try putting a print statement where you are defining the part and also put one on the start of the function before the variables.

I think you should try playerCharacter:PivotTo(--[[the part's CFrame]])

local part = script.Parent
local inuse = false -- cooldown
part.Touched:Connect(function(hit)
	if inuse then return; end -- return if in use
	local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if Player then -- checking if target player 
		inuse = true
		
		local Character = hit.Parent -- find character
		Character:PivotTo(workspace.Part.CFrame) -- change way or use local
		
		task.delay(1, function() -- cooldown
			inuse = false
		end)
	end
end)

forgot about cframe.

print("script enabled")
local part = script.Parent
print("first variable")


part.Touched:Connect(function(hit)
	local character = hit.Parent
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	print("touched event started")

	if humanoidRootPart then
		local targetCFrame = game.Workspace.Areas.Area.CFrame
		humanoidRootPart.CFrame = targetCFrame
		print("teleported")
	end
end)

Script is enabled and none of the print statements work?

I’ll try restarting studio ig.

…does your avatar have the levitation animation on? Or can you show the target part?

Ok I can provide an image but my script is a localscript inside the part, does that make any difference?

use server script , local script doesnt working in workspace

1 Like

oh i didnt know that ok charschas

Is the part located in Workspace? If so, try parenting it to StarterCharacterScript

I agree using server scripts, since it’s more secure. I’d also advice parenting the server script to ServerScriptService

Thanks, your solution worked and solved the problem

1 Like

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