hello!
im trying to make a Lightning script, the script will choose a random object form the workspace and when the script chose it i want the Lightning to spawn above that chosen object but the problem is the Lightning keep spawning and the same object how do i fix that?
the script:
local ligghting = script:WaitForChild("Configuration").Rain.LightningMain:Clone()
local lighPosiIdle = Vector3.new(0,0,0)
ligghting.Position = lighPosiIdle
repeat
wait(0.01)
local randomthunder = math.random(1,100)
--print("ThenumIs..."..randomthunder)
until randomthunder == 55
local lighting = true
if ligghting then
ligghting.Parent = game.Workspace
local randomobj = game.Workspace:GetDescendants()
local randob = randomobj[math.random(1, #randomobj)]
if randob:IsA("Model") then
if randob.Parent:FindFirstChild("Part") then
print(randob.Name)
ligghting.Position = randob.Parent:FindFirstChild("Part").Position+Vector3.new(0,20,0)
elseif randob.Parent:FindFirstChild("HumanoidRootPart") then
ligghting.Position = randob.Parent:FindFirstChild("HumanoidRootPart").Position+Vector3.new(0,20,0)
end
else
if randob:IsA("Part") then
ligghting.Position = randob.Position+Vector3.new(0,20,0)
end
end
end
end