Hello, I’m a new programmer. Actually, I love Roblox Studio too much! But, now I have a problem… When you crash, your camera bugs. It follows a part and still following it 'till it destroys or the player is dead. I think it might be happening because of SetNetworkOwner. I would really appreciate if you guys help!
Here’s the footage (Sorry for potato mic!):
Da codes:
Damager (Script)
local event = script.Parent.Parent.Parent.Damager
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Exclude
local isCooldown = false
local cooldownTime = 1.5
event.Event:Connect(function(damage, ragdollTime)
if isCooldown then return end
isCooldown = true
damage = damage * 6
local parts = workspace:GetPartsInPart(script.Parent, overlapParams)
local processedCharacters = {}
for _, part in pairs(parts) do
local character = part.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local rootPart = character:FindFirstChild("HumanoidRootPart")
if humanoid and rootPart and not processedCharacters[character] then
processedCharacters[character] = true
humanoid:TakeDamage(damage)
if damage > 20 then
humanoid.PlatformStand = true
for _, v in pairs(character:GetDescendants()) do
if v:IsA("BasePart") then
v.CollisionGroup = "Ragdoll"
elseif v:IsA("BallSocketConstraint") then
v.Enabled = true
elseif v:IsA("Motor6D") then
v.Enabled = false
end
end
task.delay(ragdollTime, function()
if not character or not character.Parent or not rootPart then return end
while rootPart and rootPart.AssemblyLinearVelocity.Magnitude > 1.5 do
task.wait(0.2)
end
if humanoid then
humanoid.PlatformStand = false
humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
for _, v in pairs(character:GetDescendants()) do
if v:IsA("BallSocketConstraint") then
v.Enabled = false
elseif v:IsA("Motor6D") then
v.Enabled = true
end
end
end)
end
end
end
task.wait(cooldownTime)
isCooldown = false
end)
VehicleScript (Script)
local MAX_SPEED = 170
local MAX_STEER = 30
local acceleration = 3
task.wait(1.6)
local vehicle = script.Parent.Chassis
local driverSeat = vehicle.DriverSeat
local motorLeft, motorRight = vehicle.MotorLeft, vehicle.MotorRight
local servoLeft, servoRight = vehicle.ServoLeft, vehicle.ServoRight
local function updateNetworkOwner(player)
for _, v in pairs(vehicle:GetDescendants()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(player)
end
end
end
driverSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
local humanoid = driverSeat.Occupant
if humanoid then
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
updateNetworkOwner(player)
else
updateNetworkOwner(nil)
end
end)
driverSeat.Changed:Connect(function(property)
if property == "ThrottleFloat" and script.Parent.Health.Value < 160 then
local velocity = MAX_SPEED * acceleration * driverSeat.ThrottleFloat
motorLeft.AngularVelocity = velocity
motorRight.AngularVelocity = velocity
elseif property == "SteerFloat" then
local angle = MAX_STEER * driverSeat.SteerFloat
servoLeft.TargetAngle = angle
servoRight.TargetAngle = angle
end
end)
Crash (Script, I don’t even know if you need this.)
local carparts = script.Parent:GetDescendants()
local crashvelo = 18
local cooldownTime = 0.5
local cooldowns = {}
local resparts = {}
for _, v in pairs(carparts) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit:IsA("BasePart") and not table.find(carparts, hit) then
if cooldowns[v] and tick() - cooldowns[v] < cooldownTime or table.find(resparts, v) then
return
end
local diffLX = math.abs(v.AssemblyLinearVelocity.X - hit.AssemblyLinearVelocity.X)
local diffLY = math.abs(v.AssemblyLinearVelocity.Y - hit.AssemblyLinearVelocity.Y)
local diffLZ = math.abs(v.AssemblyLinearVelocity.Z - hit.AssemblyLinearVelocity.Z)
local diffAX = math.abs(v.AssemblyAngularVelocity.X - hit.AssemblyAngularVelocity.X)
local diffAY = math.abs(v.AssemblyAngularVelocity.Y - hit.AssemblyAngularVelocity.Y)
local diffAZ = math.abs(v.AssemblyAngularVelocity.Z - hit.AssemblyAngularVelocity.Z)
local isLinearLow = diffLX < crashvelo or diffLY < crashvelo or diffLZ < crashvelo
local isAngularLow = diffAX < crashvelo or diffAY < crashvelo or diffAZ < crashvelo
if isLinearLow and isAngularLow then
return
else
table.insert(resparts, v)
cooldowns[v] = tick()
local rad = Instance.new("Part")
rad.Shape = Enum.PartType.Ball
rad.Parent = v
rad.Position = v.Position
rad.Anchored = true
rad.CanCollide = false
rad.Transparency = 0
Instance.new("Highlight", rad)
script.Parent.Parent.Health.Value = script.Parent.Parent.Health.Value + 1
local maxDiff = math.max(diffLX, diffLY, diffLZ)
local calculatedSize = maxDiff / 100
local damage = calculatedSize * 10
rad.Size = Vector3.new(calculatedSize, calculatedSize, calculatedSize)
local event = script.Parent.Parent.Damager
event:Fire(damage, calculatedSize)
local params = OverlapParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = carparts
local partsInPart = workspace:GetPartsInPart(rad, params)
for _, part in pairs(partsInPart) do
if part:IsA("BasePart") then
local parentModel = part:FindFirstAncestorOfClass("Model")
local humanoid = parentModel and parentModel:FindFirstChildOfClass("Humanoid")
if humanoid then
local ragdollTime = parentModel:FindFirstChild("RagdollTime")
humanoid:TakeDamage(damage)
if ragdollTime then
ragdollTime.Value = damage / 10
end
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
else
cooldowns[part] = tick()
part:BreakJoints()
end
end
end
rad:Destroy()
end
end
end)
end
end