Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to delete a model after a player gets up from a seat?

Asked by 3 years ago
Edited 3 years ago

I tried using humanoid.Seated event but it didn't work. I want to make a script that deletes the car after a player gets up from a vehicleseat. I'm kinda new and I wanna know how to do it.

--local script--
local event = script.Parent.DeleteCar
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local audi = script.Parent.Parent --the car
if not humanoid.Seated then
    event:FireServer(audi)
end

--server script--
local event = script.Parent.DeleteCar
event.OnServerEvent:Connect(function(plr, car)
    car:Destroy()
end)

i know the script is horribly wrong. I'm kinda new to scripting

0
Show us your script. Btw, you're on the right track with the humanoid.Seated part. Dovydas1118 1495 — 3y
0
i posted the script antvvnio 40 — 3y
0
It will only check once, use humanoid.Seated:Connect(function) JudgeDuckie 25 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This is very simple, just use GetProperty ChangeSignal look at the code below

local Players = game:GetService("Players")

local seat = script.Parent

local currentPlayer = nil

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    local humanoid = seat.Occupant 
    if humanoid then 
        local character = humanoid.Parent
        local player = Players:GetPlayerFromCharacter(character)
        if player then 
            currentPlayer = player
            return
        end 
    end
    if currentPlayer then 
        seat:Destroy()
    end
end)
0
ill test it when ill be home, thank you for your time! :) antvvnio 40 — 3y
Ad

Answer this question