Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My control points system won't remove and add points after one time?

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

7 comments

0

mmm, the scorekeeper script you added doesnt change the value of the "defenderOccupied" or "attackerOccupied" variables, if you have a script that changes those then adding that for reference would help

0

The script that you improved was the script that changed the value the scorekeeper just manages the score text

0

The script i improved changes the "dscore" and "ascore" variables, i need to know what is changing the "doccupy" and "aoccupy" values, since if they are always "1" idk why you'd need them...

0

they tell that the point has been captured by either team and never rise above one

0

hmmm, can you add me to a team create so i can check myself? there's definitely something im missing

0

yeah sure do you have discord so we can talk about it easier than comments

0

SerpentineKing#0155

1 answer

✓ Accepted answer

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

  1. 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.

  2. 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

3 comments

0

^

0

I'll try that thank you so much for your help

0

I tried but the problem still happens hmm. because the scorekeeper values never change for some reason i'll add the scorekeeper script for reference

This discussion is preserved as it was. New answers, comments, and votes are closed.