I’m trying to make a teleport part that works when touched while sitting down.
I had no errors in the output, and I even searched for an answer. I tried different solutions by using Humanoid.Sit = false which didn’t really help.
``function onTouched(m)
local p = m.Parent:findFirstChild(“Humanoid”)
if p ~= nil then
p.Humanoid.Sit = false
p.Torso.CFrame = CFrame.new(-231.786, 1, 28.401)
end
end
Just simply check if there’s a Player Object, if there is create a Character variable referencing the m’s Parent:
local function onTouched(m)
if game.Players:GetPlayerFromCharacter(m.Parent) then
local Character = m.Parent
Character.Humanoid.Sit = false
Character.Torso.CFrame = CFrame.new(-231.786, 1, 28.401)
end
end
script.Parent.Touched:Connect(onTouched)
function onTouched(m)
local p = m.Parent:FindFirstChild(“Humanoid”)
if p ~= nil then
p.Humanoid.Sit = false
wait()
p.HumanoidRootPart.CFrame = CFrame.new(-231.786, 1, 28.401)
end
end
script.Parent.Touched:connect(onTouched)
function onTouched(hit)
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if humanoid ~= nil then
humanoid.Sit = false
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-231.786, 1, 28.401)
end
end
script.Parent.Touched:connect(onTouched)
-- Teleport when sitting
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
local HRP = hit.Parent:FindFirstChild("HumanoidRootPart")
if Humanoid then
if Humanoid.Sit then
HRP.CFrame = CFrame.new(0, 100, 0)
end
end
end
end)
-- Teleport & make them sit
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
local HRP = hit.Parent:FindFirstChild("HumanoidRootPart")
if Humanoid then
Humanoid.Sit = true
HRP.CFrame = CFrame.new(0, 100, 0)
end
end
end)
Ok i think the only choice here is DEBUGGING
spam those prints
function onTouched(hit)
print("touched")
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if humanoid ~= nil then
print("humanoid found")
humanoid.Sit = false
print("stop sitting")
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(-231.786, 1, 28.401)
print("teleported")
end
end
script.Parent.Touched:connect(onTouched)