Basically I made dragon balls. I have DB1 - DB7 in the player data as bool value for each player. I'm trying to make it so if a player has the bool value to true, don't spawn the dragon ball. But my for loop is checking for EVERYONE if they all have it to true, don't spawn or else it does spawn. All I want is to make it so if 1 player has the bool value to true, it doesn't spawn that certain dragon ball.
Script inside dragon ball
local db = script.Parent local debounce = true function onTouch(hit) if debounce then if hit.Parent:FindFirstChild("Humanoid") then debounce = true db:Destroy() local player = hit.Parent.Name game.Players[player].Data.DB1.Value = true debounce = false end end end db.Touched:connect(onTouch)
Script you gave me waffle:
while wait(1)do for i=1,7 do local rDB=true if not workspace:FindFirstChild(i.." Star")then for _,v in next,game.Players:GetPlayers()do if v.Data["DB"..i].Value then rDB=false break end end end if rDB then game.ServerStorage[i.." Star"]:Clone().Parent=workspace end end end
In the while loop, you're calling DB1 and then DB2, etc. but DB1 is already an infinite loop, so the other ones are never going to run.
In DB1, you're calling rDB1 for every player whose DB1's value is false. You want to call rDB1 only if they are all false.
Your script is unnecessarily long and redundant. I've shortened it with a for loop and concatenation, and fixed those problems.
while wait(1)do for i=1,7 do if not workspace:FindFirstChild(i.." Star")then local rDB=true for _,v in next,game.Players:GetPlayers()do if v.Data["DB"..i].Value then rDB=false break end end if rDB then game.ServerStorage[i.." Star"]:Clone().Parent=workspace end end end end
edit:
On line 7 the script is destroyed and the program is terminated. If you're going to destroy it, nothing can happen afterwards, so it should be the last thing.
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid")then game.Players[hit.Parent.Name].Data.DB1.Value=true script.Parent:Destroy() end end)