So im testing out my control points system and it adds the point of the first capture but never removes and adds the point of the second capture? Hoping someone can help.
local pointAddedDefender = false local pointAddedAttacker = false while true do wait(0.00001) if script.Parent.defenderOccupied.Value == 1 and pointAddedDefender == false then pointAddedDefender = true pointAddedAttacker = false game.Workspace.scoreKeeper.defendersPoints.Value = game.Workspace.scoreKeeper.defendersPoints.Value + 1 if game.Workspace.scoreKeeper.attackersPoints.Value >=1 then game.Workspace.scoreKeeper.attackersPoints.Value = game.Workspace.scoreKeeper.attackersPoints.Value - 1 pointAddedAttacker = false end end if script.Parent.attackerOccupied.Value == 1 and pointAddedAttacker == false then pointAddedAttacker = true pointAddedDefender = false game.Workspace.scoreKeeper.attackersPoints.Value = game.Workspace.scoreKeeper.attackersPoints.Value + 1 if game.Workspace.scoreKeeper.defendersPoints.Value >=1 then game.Workspace.scoreKeeper.defendersPoints.Value = game.Workspace.scoreKeeper.defendersPoints.Value - 1 pointAddedDefender = false end end end
Here is the scorekeeper script for reference
local hint = Instance.new("Hint") hint.Parent = workspace while true do wait(0.1) hint.Text = "Worm Cult Points: " .. script.defendersPoints.Value .. " Hostile points: " .. script.attackersPoints.Value end
Improvements
Use local variables when you need to use the same instance multiple times
Roblox's Frames are set to approximately 0.03 seconds, anything lower than that is a little extreme
Potential Issues
I'd like to preface this with saying there is nothing wrong with the code provided
If this script is a Local Script, then changes are not being made on the server, only on the Client, so this would need to be transferred to a server script.
The "doccupy" and "aoccupy" variables (as seen below) must be "1" for the code to run. If you change this value to anything other than 1 the code will not run, so if this value only gets larger after reaching "1" in some other script of yours, then the check is false.
Revised Server Script
local pointAddedDefender = false local pointAddedAttacker = false local folder = script.Parent local doccupy = folder:WaitForChild("defenderOccupied") local aoccupy = folder:WaitForChild("attackerOccupied") local score = workspace:WaitForChild("scoreKeeper") local dscore = score:WaitForChild("defendersPoints") local ascore = score:WaitForChild("attackersPoints") while true do wait(0.03) if doccupy.Value == 1 and pointAddedDefender == false then pointAddedDefender = true pointAddedAttacker = false dscore.Value = dscore.Value + 1 if ascore.Value >= 1 then ascore.Value = ascore.Value - 1 end end if aoccupy.Value == 1 and pointAddedAttacker == false then pointAddedDefender = false pointAddedAttacker = true ascore.Value = ascore.Value + 1 if dscore.Value >= 1 then dscore.Value = dscore.Value - 1 end end end