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

why wont this script work?

Asked by
Benqazx 108
8 years ago
local owner = script.Parent.Parent.Parent.Owner.Value
local ownerfound = game.Players:FindFirstChild(owner)
local model = script.Parent.Parent.Parent.Model.Value

repeat wait()
until ownerfound == nil
if ownerfound == nil then
    script.Parent.Parent.Parent:Destroy()
end

this script is in a car. i am trying to make it destroy a car if its owner is not in the game. so it the owner is not found in the game then the car will be destroyed. it wont destroy the car when owner is not found. please can you help me its my first question on this website please someone help me with this

1 answer

Log in to vote
0
Answered by 8 years ago

Try this:

local owner = script.Parent.Parent.Parent.Owner.Value
local ownerfound = game.Players:FindFirstChild(owner)
local model = script.Parent.Parent.Parent.Model.Value


while wait() do
game.Players.PlayerRemoving:connect(function(player)
    if player.Name = ownerfound then
        model:Remove()
        wait(0.1)
    end
end)
end

--{ Basically what is happening is that once the player is leaving the game, it will check if that players name is the one that matches the owner name, if it is, then destroy the car. }--

0
thanks for your answer although i figured it out but this was better then mine thank you Benqazx 108 — 8y
0
Glad I could help! XmarineALT 25 — 8y
Ad

Answer this question