Hello, So I am attempting to create a teleport script to use as an elevator in one of the games I am working on, however my script is not running. It's a localscript in a part to test as a button (regular script was doing the same thing, however giving me an error saying that "player" was a nil value while it was a parameter in onClick) There are no errors in the output, could anyone let me know if there's something I'm doing wrong?

-- elevator trial

local b = script.Parent
local fL = script.Parent.Parent
local f1 = game.Workspace.Elevator.floor1

function onClick(player)
	local p = player.Parent:FindFirstChild("Humanoid")
	if (p ~= nil) then
		p.Parent.Torso.CFrame = f1.CFrame + CFrame.new(Vector3.new(0,3,0))
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)
print("worked! :D") -- just here see if the script was running, i'm getting nothing in the output

9 comments

0

well, p(the part where you tried to find the humanoid) is nil, because the humanoid isn't located there, it is inside Player.Character,

0

so would i change it to: local p = player.Character:FindFirstChild("Humanoid")

0

^ still doesnt work

0

Edit line 08: local p = player.Character:FindFirstChild("HumanoidRootPart")

0

^ its his choice

0

still not working

0

Is it a local script?

0

Try Changing f1 variable to FloorOne and adjust.

0

add a print inside the if statement (where you set the Torso's CFrame)