This script is for a random weapons crate in my game, however I also have aliens roaming around. When one of these aliens runs into a weapons crate the script instantly breaks with the response : "Alien is not a valid member of Players." How would I make it so that if anything other than a player touches it, the script doesn't break?
script.Parent.Touched:connect(function(hit)
script.Disabled = true
local player = hit.Parent.Name
local random = math.random(1,100)
if random > 0 and random < 23 then
local laserSword = game.ServerStorage.LaserSword:Clone()
laserSword.Parent = game.Players[player].Backpack
elseif random > 23 and random < 61 then
local sCAR = game.ServerStorage.SCAR:Clone()
sCAR.Parent = game.Players[player].Backpack
elseif random > 61 and random < 100 then
local weapon7 = game.ServerStorage.Weapon7:Clone()
weapon7.Parent = game.Players[player].Backpack
end
script.Parent:Destroy()
end)
end
end)

1 comment
Thanks so much it works!