What do you want to achieve? I want to know when the player leaves/reset so that I can despawn a car.
What is the issue? I am having trouble trying to find ways to do so.
What solutions have you tried so far? Alot of the solutions didn’t work for my case.
local Tool = script.Parent
local debounce = false
local player = script.Parent.Parent
local Players = game:GetService("Players")
script.Parent.Activated:Connect(function()
if debounce == false then
debounce = true
local Build = game.ReplicatedStorage.MailTruck:Clone()
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == Tool.Parent.Name.."'s MailTruck" then
v:Destroy()
end
end
Build.Parent = game.Workspace
Build:SetPrimaryPartCFrame(Tool.Parent.HumanoidRootPart.CFrame + Vector3.new(15,0,0))
Build.Name = Tool.Parent.Name.."'s ".."MailTruck"
wait(1)
debounce = false
end
end)
local Tool = script.Parent
local debounce = false
local char
local Players = game:GetService("Players")
local playerofthistool
script.Parent.Activated:Connect(function()
char = script.Parent.Parent
playerofthistool = Players:GetPlayerFromCharacter(char)
if debounce == false then
debounce = true
local Build = game.ReplicatedStorage.MailTruck:Clone()
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == Tool.Parent.Name.."'s MailTruck" then
v:Destroy()
end
end
Build.Parent = game.Workspace
Build:SetPrimaryPartCFrame(Tool.Parent.HumanoidRootPart.CFrame + Vector3.new(15,0,0))
Build.Name = Tool.Parent.Name.."'s ".."MailTruck"
wait(1)
debounce = false
end
end)
Players.PlayerRemoving:Connect(function(supposedplayer)
if supposedplayer == playerofthistool then
print('Hooplah!')
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == playerofthistool.Name.."'s MailTruck" then
v:Destroy()
end
end
end
end)
local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Tool = script.Parent
local debounce = false
local char
local playerofthistool
local function DestroyPlayersTruck(player : Player)
local truck = workspace:FindFirstChild(player.Name.."'s MailTruck")
if truck then
truck:Destroy()
truck = nil
end
end
Tool.Activated:Connect(function()
char = script.Parent.Parent
playerofthistool = Players:GetPlayerFromCharacter(char)
if not debounce then
debounce = true
DestroyPlayersTruck(playerofthistool)
local Build = ReplicatedStorage.MailTruck:Clone()
Build.Parent = workspace
Build:PivotTo(Tool.Parent.HumanoidRootPart.CFrame + CFrame.new(15, 0, 0))
Build.Name = char.Name.."'s ".."MailTruck"
task.delay(1, function()
debounce = false
end)
end
end)
Players.PlayerRemoving:Connect(function(player)
if player == playerofthistool then
DestroyPlayersTruck(player)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == Player.Name.."'s MailTruck" then
v:Destroy()
end
end
end)