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

Why can't it get through this is if statement?

Asked by
DesertusX 435 Moderation Voter
4 years ago
Edited 4 years ago

I tried writing prints but the only one that successfully sent a console message was the first one. What I am trying to make is a part that gives a value to the other team when touched. I do call the function later on in the script. I get no errors in the output whatsoever.

local p = script.Parent
local w = workspace
local r = w.RedScore
local b = w.BlueScore

print"Variables"

function Touch(hit) 
    if hit.Parent:FindFirstChild("Humanoid")then
        print"Humanoid"
        if hit.Parent.TeamColor == BrickColor.new("Bright blue")then
            r = r + 1
            elseif 
                hit.Parent.TeamColor == BrickColor.new("Bright red")then
                    b = b +1
            end
            print"If"
        end 

Thanks for helping. :)

0
Are there BrickColor values inside the character? Or are you using roblox's classic team system? SnowieDev 171 — 4y
0
The classic system. DesertusX 435 — 4y
0
Alright. SnowieDev 171 — 4y
0
Are the RedScore and BlueScore values? Like Number or Int Values? SnowieDev 171 — 4y
View all comments (4 more)
0
Yes. IntValues. DesertusX 435 — 4y
0
Alright. SnowieDev 171 — 4y
0
What's the name of the Blue and Red team inside the explorer panel? SnowieDev 171 — 4y
0
Blue and Red. DesertusX 435 — 4y

2 answers

Log in to vote
1
Answered by
SnowieDev 171
4 years ago

This might work.

local p = script.Parent
local w = workspace
local r = w.RedScore
local b = w.BlueScore

print"Variables"

function Touch(hit) 
    if hit.Parent:FindFirstChild("Humanoid") then
        print"Humanoid"
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Player.Team == game.Teams.Blue then
            r.Value = r.Value + 1
        elseif Player.Team == game.Teams.Red then
            b.Value = b.Value +1
        end
        print"If"
    end
end 
0
Sorry, doesn't work. DesertusX 435 — 4y
1
Never mind, I did some tweaking and now it works! Thanks! DesertusX 435 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

You need to call the function on an event.

This should work.

local p = script.Parent
local w = workspace
local r = w.RedScore
local b = w.BlueScore

print"Variables"

function Touch(hit) 
    if hit.Parent:FindFirstChild("Humanoid")then
        print"Humanoid"
        if hit.Parent.TeamColor == BrickColor.new("Bright blue")then
            r = r + 1
            elseif 
                hit.Parent.TeamColor == BrickColor.new("Bright red")then
                    b = b +1
            end
            print"If"
      end 
end

script.Parent.Touched:Connect(Touch)
0
He said he does call the function later on in the script. SnowieDev 171 — 4y

Answer this question