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

Why are my number values not adding?

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

2 comments

0

Just a comment, but do you ever do anything with the Debounce?

0

line 7

1 answer

✓ Accepted answer

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

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