I’m using raycasting to make the player’s character be in a “safe” position when leaving the vehicle. The issue with this is that, the script for doing it breaks my game basically
I have already identified that this is the script causing problems (Server Script)
local Players = game:GetService("Players")
local seat = script.Parent
local car = seat.Parent
local LeaveAttach = seat:WaitForChild("ExitPos")
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
local player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
seat:SetAttribute("Current_Occupant", player.UserId)
else
local leavingOccupant = Players:GetPlayerByUserId(seat:GetAttribute("Current_Occupant"))
local character = leavingOccupant.Character
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {car, character}
RayParams.FilterType = Enum.RaycastFilterType.Exclude
local tpdistance = -8
local ray = workspace:Raycast(character.PrimaryPart.Position, seat.CFrame.LookVector * tpdistance, RayParams)
local pos = seat.Position + seat.CFrame.RightVector * (ray and ray.Distance or tpdistance)
character.PrimaryPart.Position = pos
seat:SetAttribute("Current_Occupant", nil)
end
end)
Here’s the script that just stops working when I enter and then leave the vehicle
local WeldConstraint = R15:FindFirstChildOfClass("WeldConstraint")
WeldConstraint:GetPropertyChangedSignal("Enabled"):Connect(function()
local DustEmitter = ExplosionAttach:WaitForChild("Dust")
local FlashEmitter = ExplosionAttach:WaitForChild("Flash")
local SmokeEmitter = ExplosionAttach:WaitForChild("Smoke")
local ExplosionLight = ExplosionEmit:WaitForChild("ExplosionLight")
if R15:HasTag("HasAlreadyExploded") then
for _,fireworkchild in pairs(R15:GetChildren()) do
if fireworkchild:IsA("BasePart") or fireworkchild:IsA("Part") then
fireworkchild.Anchored = true
end
end
else
ProximityPrompt:Destroy()
R15:AddTag("HasAlreadyExploded")
-- There's more code but it's unrelated
end
end)
This video shows what happens: