local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")
local CLOUD_MODEL = script.Parent
local ALL_PATHS = CLOUD_MODEL:WaitForChild("AllPaths")
local CLOUDS = {}
local debounce = false
local LightningToggle = CLOUD_MODEL:WaitForChild("Lightning")
local CLOUD_PLATFORM:Part = nil
local MODELS = ReplicatedStorage:WaitForChild("Models")
local Lightning = MODELS:WaitForChild("Lightning")
local Sounds = ReplicatedStorage:WaitForChild("Sounds")
local LightningStrike = Sounds:WaitForChild("Lightning Strike 3")
for i, Cloud in ALL_PATHS:GetDescendants() do
if Cloud:IsA("Model") then
table.insert(CLOUDS, Cloud)
else
continue
end
end
task.spawn(function()
while true do
if LightningToggle == true then return end
local RandomNumber = math.random(1, 100)
if RandomNumber <= 100 then
LightningToggle = true
local RandomCloud = CLOUDS[math.random(1, #CLOUDS)]
local CLOUD_MESH = RandomCloud:FindFirstChild("Cloud")
CLOUD_PLATFORM = RandomCloud:FindFirstChild("CloudPlatform")
TweenService:Create(CLOUD_MESH, TweenInfo.new(3, Enum.EasingStyle.Linear), {Color = Color3.fromRGB(0, 0, 0)}):Play()
task.wait(math.random(5, 10))
LightningToggle = false
CLOUD_PLATFORM = nil
TweenService:Create(CLOUD_MESH, TweenInfo.new(3, Enum.EasingStyle.Linear), {Color = Color3.fromRGB(255, 255, 255)}):Play()
CLOUD_MESH = nil
else
task.wait(1)
continue
end
end
end)
CLOUD_PLATFORM.Touched:Connect(function(hit)
if debounce == true or LightningToggle == false then return end
debounce = true
local Head:Part = hit.Parent:FindFirstChild("Head")
local Humanoid:Humanoid = hit.Parent:FindFirstChild("Humanoid")
local LightningClone = Lightning:Clone()
LightningClone.Parent = game.Workspace
LightningClone:PivotTo(CFrame.new(Head.Position + Vector3.new(0, 60, 0)))
local LightningSoundClone = LightningStrike:Clone()
LightningSoundClone.Parent = Head
LightningSoundClone:Play()
Humanoid.Health -= 20
Humanoid.Sit = true
Debris:AddItem(LightningClone, 2)
Debris:AddItem(LightningSoundClone, 2)
task.wait(5)
debounce = false
end)
I don’t know how to explain it so I’ll use an example instead.
There’s a table that includes a 3 models named Cloud1, Cloud2, and Cloud3 and all of them have a platform under them. When I test the game and the server chooses a random cloud (guranteed for testing purposes). Let’s say it picks Cloud1. Cloud1 will forever lightning strike a player even when the server picks a random different cloud. I have no idea how to fix this. I tried my best to explain it. I hope you understand.