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

Script breaks if 'horse' is not found, how can I avoid this?

Asked by
RoyMer 301 Moderation Voter
9 years ago

The Marked line is the cause of the script breaking if 'horse' is not found, how can I avoid this?

Is it possible to do? if Horse is found then continue? if Horse is not found then continue anyways?

owner = script.Parent.Parent.Parent.OwnerName

function onTouched(hit) 
    local check = hit.Parent:FindFirstChild("Humanoid") 

    if check ~= nil then
    if hit.Parent.Name == owner.Value then 

    if script.Parent.Ready.Value == true then
    script.Parent.Parent.Horse:Destroy()  <----THIS LINE    
    script.Parent.Ready.Value = false

    local clone = game.ReplicatedStorage.TycoonModels.Horse:Clone()
    clone.Parent = script.Parent.Parent
    clone.Position = script.Parent.Parent.HorseSpawnPoint
            end 
        end 
    end 
    wait(10)
    script.Parent.Ready.Value = true    
end
script.Parent.Touched:connect(onTouched) 

Answer this question