0
votes

My objective is to make a variable (_G.rownedB and _G.gownedB) that adds points to _G.RPoints or _G.GPoints 1 per 1 second until either one of them has 1200 points. Unfortunately, it does not seem to be functioning correctly and is instead failing to work at all, launching the game and seeing that when I capture the point, the point gui text (_G.News.Text) does not work. What is my mistake?

-- Script by Dropdatderp
capturing = nil
_G.rownedB = false
_G.gownedB = false
neutral = true
function get_player(part)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if part:IsDescendantOf(player.Character) then
            return player
        end
    end
end
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h ~= nil then
    if _G.gownedB or neutral == true then
        capturing = true
        _G.News.Text = "Raiders are taking Point B!"
        wait(10)
        _G.News.Text = "Raiders have taken Point B."
        capturing = nil
        _G.rownedB = true
        _G.gownedB = false
        neutral = false
    end
    elseif _G.rownedB or neutral == true then
        local player = get_player(part)
        if player:IsInGroup("901313") then
            capturing = true
            _G.News.Text = "Defenders are taking Point B!"
            wait(10)
            _G.News.Text = "Defenders have taken Point B."
            capturing = nil
            _G.rownedB = false
            _G.gownedB = true
            neutral = false
            repeat
                wait(1)
                _G.RPoints = _G.RPoints + 1
            until _G.RPoints or _G.GPoints == 1200
        end
    end
end
repeat
script.Parent.Touched:connect(get_player)
script.Parent.Touched:connect(onTouched)
until _G.GPoints == 1200 or _G.RPoints == 1200
1

1 Answers

0
votes

For start, check your if statments. Is this like you wanted it?

if h ~= nil then
  if _G.gownedB or neutral == true then

  end
elseif _G.rownedB or neutral == true then

  if player:IsInGroup("901313") then

  end

end

or rather

if h ~= nil then
  if _G.gownedB or neutral == true then

  elseif _G.rownedB or neutral == true then
    if player:IsInGroup("901313") then

    end

  end
end

??

Also make sure that you understand what this line does:

script.Parent.Touched:connect(onTouched)

and ask yourself it makes any sense to call it multiple times. Will you ever leave that repeat until statement??

Are you missing something here?

repeat
  wait(1)
  _G.RPoints = _G.RPoints + 1
until _G.RPoints or _G.GPoints == 1200

Will this do anything useful?

Read through your code carefully, ask yourself what you want to do and what is happening. Draw a simple flow chart or decision tree and play several cases...