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

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

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

3 comments

0

Show us your script. Btw, you're on the right track with the humanoid.Seated part.

0

i posted the script

0

It will only check once, use humanoid.Seated:Connect(function)

1 answer

✓ Accepted answer

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)

1 comment

0

ill test it when ill be home, thank you for your time! :)

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