Need Help WIth PrimaryPartCFrame

Basically what I was trying to do was script a system that when a player touched the detector it would take them to the seat, kind of similar to most camping games system,

Screenshot_160

The Touch Event is working so I can only assume that something is wrong with my CFrame and I’ve been stuck on this for quite an while

Plase, don’t send images instead of scripts. Try this on the line 6:

player.Character:SetPrimaryPartCFrame(CFrame.new(seatCFrame))

are you sure seatCFrame is a CFrame and not a part/seat?

And, connect is deprecated. Use Connect

I made the changes to my script and and tried to find out what the issue was
function onTouch(hit)
local player = hit.Parent:FindFirstChild(“Humanoid”)
–player.Torso:Destroy()
script.Parent.Transparency = 0
player.Character:SetPrimaryPartCFrame(CFrame.new(0,500,0))
end

script.Parent.Touched:Connect(onTouch)

I Tried Setting the CFrame to a number but nothing happened, TouchEvent occured but the player didn’t teleport

This happens because you can’t change the CFrame of a humanoid, try this:

function onTouch(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
script.Parent.Transparency = 0
player.Character:SetPrimaryPartCFrame(CFrame.new(seatCFrame))
end
end

script.Parent.Touched:Connect(onTouch)
1 Like

wait so I needed to get the Player From Character ?

Yes, but if you don’t want you can try this:

function onTouch(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human then
script.Parent.Transparency = 0
hit.Parent:SetPrimaryPartCFrame(CFrame.new(seatCFrame))
end
end

thanks I’ll keep this in mind when I’m trying to move players since I’m new at scripting

1 Like