Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
kom297 -4
5 years ago
Edited 5 years ago

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
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 SerpentineKing 3885 — 5y
0
The script that you improved was the script that changed the value the scorekeeper just manages the score text kom297 -4 — 5y
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... SerpentineKing 3885 — 5y
0
they tell that the point has been captured by either team and never rise above one kom297 -4 — 5y
View all comments (3 more)
0
hmmm, can you add me to a team create so i can check myself? there's definitely something im missing SerpentineKing 3885 — 5y
0
yeah sure do you have discord so we can talk about it easier than comments kom297 -4 — 5y
0
SerpentineKing#0155 SerpentineKing 3885 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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
0
^ EmbeddedHorror 299 — 5y
0
I'll try that thank you so much for your help kom297 -4 — 5y
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 kom297 -4 — 5y
Ad

Answer this question