Player doesn't get teleported

Greetings,

I have a part that when the player touches it, the part sends an event that triggers another script. The script teleports the player so that he cannot reactivate the part by hitting it again. I have problems with teleporting the player, please help. The script is down below:

The script

local player = game.Players.LocalPlayer
local OpenMenuEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarMechanicJob1").OpenJobGUI
local CloseMenuEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarMechanicJob1").CloseJobGUI

OpenMenuEvent.Event:Connect(function(player)
	local RootPart = player:FindFirstChild("HumanoidRoot")
	RootPart.CFrame = CFrame.new(-30.605, 4.221, 1256.933)  ---Problematic line... (7)
	workspace.CurrentCamera.CameraType = "Scriptable"
	workspace.CurrentCamera.CFrame = workspace.CarMechanicJob1.JobCamera.CFrame
	script.Parent.Visible = true
end)

The error

it’s “HumanoidRootPart” and not “HumanoidRoot” and is a parent of character, not player.

1 Like

HumanoidRootPart is child of Character, not Player
There is no such thing ‘HumanoidRoot’ in the player. It has ‘HumanoidRootPart’ inside the character, not the player.

1 Like

Ok but what about my actual problem? Line 7… Not 6. The error is listed in the post description

Replace your code with this :

local player = game.Players.LocalPlayer
local OpenMenuEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarMechanicJob1").OpenJobGUI
local CloseMenuEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarMechanicJob1").CloseJobGUI

OpenMenuEvent.Event:Connect(function(player)
	local RootPart = player.Character:FindFirstChild("HumanoidRootPart")
	RootPart.CFrame = CFrame.new(-30.605, 4.221, 1256.933)  ---Problematic line... (7)
	workspace.CurrentCamera.CameraType = "Scriptable"
	workspace.CurrentCamera.CFrame = workspace.CarMechanicJob1.JobCamera.CFrame
	script.Parent.Visible = true
end)

It should work now.

1 Like

Great solution! Works flawlessly! Is there a way I can add a cooldown that will make the part not work when touched for like (example) 10 seconds from the first time a player touches it? Whenever I touch it, it just goes wild with about 100+ touches.

1 Like

Of course! You can use debounces [ variables] to add a delay,
if you need help with debounces, I made a quick tutorial on it

1 Like

Alright, where can I find the tutorial? Idk how to use denounces. Thanks!

https://devforum.roblox.com/t/what-are-debounces-and-how-to-use-them/1725060

1 Like

Thank you for all the help! I’m gonna look into it!

1 Like

this is what i do
local script in starterpack:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humrp = char:WaitForChild("HumanoidRootPart")

normal script in serverscriptservices:

game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humrp = char:WaitForChild("HumanoidRootPart")
end)