Here's a question, can I perform operations with number of values returned by a table? My thought is to make a simple voting system that checks the number of votes against the number of players until it reaches a 2/3 majority. For some reason though this checking script causes the entire place to lock up when it runs. I think it's to do with dividing by the #pls number.
function update(child) local votes = script:WaitForChild("Votes").Value if child.Name == "Votes" then return else votes = votes + 1 end local pls = game.Players:GetChildren() -- pt. 2 of the problem if (votes / #pls) > 0.6 then -- I think this line is the problem local new = game.ServerStorage.Ball:Clone() if game.Workspace:FindFirstChild("Ball") then game.Workspace.Ball:Destroy() end new.Parent = game.Workspace new.Position = Vector3.new(-49, 17.4, 27.034) script:ClearAllChildren() wait() local vt = Instance.new("IntValue") vt.Name = "Votes" vt.Parent = script end end script.ChildAdded:connect(update)
Of course you can!
The problem is the way you are counting the vote total, I think. After getting any single vote, you never actually increment the total. Save votes
back out to script.Votes.Value
.
But eliminate the "Votes" object, really. Just use a variable! It's much cleaner and simpler.
local votes = 0; function update(child) votes = votes + 1 local pls = game.Players:GetChildren() -- pt. 2 of the problem if (votes / #pls) > 0.6 then -- I think this line is the problem local new = game.ServerStorage.Ball:Clone() if game.Workspace:FindFirstChild("Ball") then game.Workspace.Ball:Destroy() end new.Parent = game.Workspace new.Position = Vector3.new(-49, 17.4, 27.034) script:ClearAllChildren() wait() votes = 0; end end script.ChildAdded:connect(update)
You really should probably find something better than ChildAdded, but that works.