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

Why are my number values not adding?

Asked by
jacobwow 140
9 years ago

This script is a goal system. There may be more than one broken part.

local Goal = script.Parent
local debounce = false
local GoalVal = script.Parent.Goals.Value

function onTouch(part)
    local Ball = part.Parent:findFirstChild("ScoreBall")
    if Ball ~= nil and debounce == false then
        local Mes = Instance.new("Message")
        Mes.Text = "Blue Team Scored!"
        Mes.Parent = game.Workspace
        GoalVal = GoalVal + 1 -- Might be here
        wait(5)
        local pl = game.Players:GetChildren()
        for i=1,#pl do
        pl[i].Character.Humanoid.Health = 0
        Mes:Remove()
        end
    end
    end

Goal.Touched:connect(onTouch)

function Endgame()
    wait(4.9)
    local pla = game.Players:GetChildren()
        for i=1,#pla do
        pla[i].TeamColor = "Lavender"
    end
end

if GoalVal.Value == 2 then Endgame()
end

0
Just a comment, but do you ever do anything with the Debounce? RedCombee 585 — 9y
0
line 7 jacobwow 140 — 9y

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

The problem here is that you assigned the values of the NumberValues to a variable. If you're going to do this, you can't add them together directly. Try this:

local Goal = script.Parent
local debounce = false
local GoalVal = script.Parent.Goals --Just gets the NumberValue, not the Value of it.

function onTouch(part)
    local Ball = part.Parent:findFirstChild("ScoreBall")
    if Ball ~= nil and debounce == false then
        local Mes = Instance.new("Message")
        Mes.Text = "Blue Team Scored!"
        Mes.Parent = game.Workspace
        GoalVal.Value = GoalVal.Value + 1 -- Gets the value property
        wait(5)
        local pl = game.Players:GetChildren()
        for i=1,#pl do
        pl[i].Character.Humanoid.Health = 0
        Mes:Remove()
        end
    end
    end

Goal.Touched:connect(onTouch)

function Endgame()
    wait(4.9)
    local pla = game.Players:GetChildren()
        for i=1,#pla do
        pla[i].TeamColor = "Lavender"
    end
end

if GoalVal.Value == 2 then Endgame()
end

As far as I see, I should've fixed it. If anything else comes up, leave a comment below, and I'll see what I can do. Hope I helped :P

Ad

Answer this question