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)

2 comments
The two functions will each get their own thread which means they can run simultaneously. If this is not intended behavior, add in a boolean value to keep of the state across both functions.
Thanks, that's simple enough to understand. It seems my definition of what a thread is was a little bit skewed I was under the impression every script is assigned a thread to run its code