Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

SetPrimaryPartCFrame is not working? [SOLVED]

Here is my script:

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent.Parent.VehicleSeat
local Players = game:GetService("Players")

local player = nil
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		print("Player got on the car")
		local humanoid = seat.Occupant
		proximityPrompt.Enabled = false
		local character = humanoid.Parent
		player = Players:GetPlayerFromCharacter(character)
		if player then 
			for i,v in pairs(script.Parent.Parent.Parent.Parent:GetDescendants()) do
				if v:IsA("BasePart")then
					v.Anchored = false
				end
			end
			
		end	
		script.Parent.Parent.Parent.Seat.ProximityPrompt.Enabled = false
	else
		print("Player got off the car")
		proximityPrompt.Enabled = true

		for i,v in pairs(script.Parent.Parent.Parent.Parent:GetDescendants()) do
			if v:IsA("BasePart")then
				v.Anchored = true
			end
		end
		local character = player.Character
		character:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent.Part.CFrame)
		player = nil
		script.Parent.Parent.Parent.Seat.ProximityPrompt.Enabled = true
	end


end)
proximityPrompt.Triggered:Connect(function(player)
	seat:Sit(player.Character.Humanoid)
end)

This is the part that's not working:

local character = player.Character
character:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent.Part.CFrame)

There are no bugs or errors in output. I don't know why it's not working. I also tried CFrame.new with the position of the part. I checked if the part still existed, which it did. I tried printing the position of the part, which worked fine. But it just won't teleport the player to the part. Any help would be great :)

1 answer

After hours of hard work and effort, i solved the issue. And it was disappointing. I need a wait() before the teleport. I just died

This discussion is preserved as it was. New answers, comments, and votes are closed.