So, I made a script to where if a player touches a block, it will teleport them to the position I want them to teleport to. Problem is, when I did this, the player won't teleport. I am a complete noob at scripting with lua so I make seeming simple mistakes often.
local teleport = script.Parent local playerCFrame = game.Workspace.Player.HumanoidRootPart.CFrame local function playerHit(part) local parent = part.Parent if game.Players:GetPlayerFromCharacter(parent) then playerCFrame = CFrame.new(Vector3.new(-50, 12, -973.5)) end end teleport.Touched:connect(playerHit)
EDIT: Player might be a placeholder name
Hey, This is just simple. You can make a part named location in workspace that the player is moved to when he touches this script's Parent. Put this in a server script. The script's Parent should be the part you have to touch to teleport.
local Part = script.Parent local Location = game.Workspace.location.Position Part.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local Character = hit.Parent Character:MoveTo(location) end end)
~~ Halwa
Hey IamTewsmrt,
local cframe = workspace.Part.CFrame; -- Pretend the CFrame value is: 0, 0, 0. local other_part = workspace.OtherPart; -- Pretend the CFrame of this part is: 5, 5, 5. cframe = other_part.CFrame; -- After that all you have done is set: CFrame.new(0, 0, 0) to CFrame.new(5, 5, 5);
local part = script.Parent; local root = workspace:WaitForChild("Player1").HumanoidRootPart; local cframe = root.CFrame; function touched(hit) local hum = hit.Parent:FindFirstChild("Humanoid"); if hum then cframe = CFrame.new(Vector3.new(-50, 12, -973.5)); root.CFrame = cframe; end end part.Touched:Connect(touched);
-- EDIT:
So, apparently it won't work in the game for you. Well, the simple answer to that is because in the game your character isn't named "Player1" it's your actual name and you are trying to get the Character "Player1", which doesn't exist in the game. So, I recommend defining the root and cframe inside of the function after you check if the humanoid exists. However, don't define the root as:
local root = workspace:WaitForChild("Player1").HumanoidRootPart;
rather, define it as:
local root = hit.Parent:WaitForChild("HumanoidRootPart");
~~ KingLoneCat