Hello, so I’ve been trying to make a script that will remove the tools from the player when sitting in a seat(Car seat, or just a normal seat), then when the player gets up it adds the tools back, the script won’t work and I don’t see what’s wrong with it(Script is below) also just note I am new to scripting.
Notes: I have a folder in ServerStroage called “toolsFolder” witch will move all the player’s tools into that folder
Script:
local Driverseat = script.Parent
local function onPlayerSit(player)
for _, tool in ipairs(player.Backpack:GetChildren()) do
if tool:IsA("Tool") then
tool:Destroy()
end
end
end
local function onPlayerExit(player)
local toolsFolder = game.ServerStorage:FindFirstChild("Tools")
if toolsFolder then
for _, tool in ipairs(toolsFolder:GetChildren()) do
if tool:IsA("Tool") then
tool:Clone().Parent = player.Backpack Backpack
end
end
end
end
Driverseat:GetPropertyChangedSignal("Occupant"):Connect(function()
local occupant = Driverseat.Occupant
if occupant then
local player = game.Players:GetPlayerFromCharacter(occupant.Parent)
if player then
onPlayerSit(player)
end
else -- If no occupant (player exited)
local player = game.Players:GetPlayerFromCharacter(Driverseat.Occupant.Parent)
if player then
onPlayerExit(player)
end
end
end)