So I wrote this yesterday and while at school I realized that inside each function I wait 8 minutes and 12 minutes respectively. Why can the other function in the script run while the opposite function is on the wait time I thought this would occupy the thread?
It's not an error or anything; the script works as planned. I'm just worried it might mess up and error at some point during gameplay
local blueCrystal = game.Workspace:WaitForChild("Blue_Crystal") local blueClickDetector = blueCrystal.ClickDetector local isBlueSpawned = true local redCrystal = game.Workspace:WaitForChild("Red_Crystal") local redClickDetector = redCrystal.ClickDetector local isRedSpawned = true --Blue Code function onBlueClicked(player) if isBlueSpawned == true then isBlueSpawned = false local playerHumanoid = player.Character.Humanoid playerHumanoid.WalkSpeed = 40 for i = 0, 1, .1 do wait() blueCrystal.Transparency = i end blueCrystal:Destroy() wait(480) local newCrystal = game.ReplicatedStorage.Blue_Crystal:Clone() newCrystal.Parent = game.Workspace blueCrystal = newCrystal blueClickDetector = newCrystal.ClickDetector blueClickDetector.MouseClick:Connect(onBlueClicked) isBlueSpawned = true end end --Red Code function onRedClicked(player) if isRedSpawned == true then isRedSpawned = false local sniper = game.ReplicatedStorage["sniper gang"]:clone() sniper.Parent = player.Backpack for i = 0, 1, .1 do wait() redCrystal.Transparency = i end redCrystal:Destroy() wait(720) local newCrystal = game.ReplicatedStorage.Red_Crystal:Clone() newCrystal.Parent = game.Workspace redCrystal = newCrystal redClickDetector = newCrystal.ClickDetector redClickDetector.MouseClick:Connect(onRedClicked) isRedSpawned = true end end --Black Code redClickDetector.MouseClick:Connect(onRedClicked) blueClickDetector.MouseClick:Connect(onBlueClicked)
Every Event fires each of its connected functions on new threads. This can be simulated with BindableEvents. You can also run a function on a separate thread directly using coroutines, or the spawn function, or the delay function.