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
5 years ago
Edited 5 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.

01local p = script.Parent
02local w = workspace
03local r = w.RedScore
04local b = w.BlueScore
05 
06print"Variables"
07 
08function Touch(hit)
09    if hit.Parent:FindFirstChild("Humanoid")then
10        print"Humanoid"
11        if hit.Parent.TeamColor == BrickColor.new("Bright blue")then
12            r = r + 1
13            elseif
14                hit.Parent.TeamColor == BrickColor.new("Bright red")then
15                    b = b +1
16            end
17            print"If"
18        end

Thanks for helping. :)

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

2 answers

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

This might work.

01local p = script.Parent
02local w = workspace
03local r = w.RedScore
04local b = w.BlueScore
05 
06print"Variables"
07 
08function Touch(hit)
09    if hit.Parent:FindFirstChild("Humanoid") then
10        print"Humanoid"
11        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
12        if Player.Team == game.Teams.Blue then
13            r.Value = r.Value + 1
14        elseif Player.Team == game.Teams.Red then
15            b.Value = b.Value +1
16        end
17        print"If"
18    end
19end
0
Sorry, doesn't work. DesertusX 435 — 5y
1
Never mind, I did some tweaking and now it works! Thanks! DesertusX 435 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

You need to call the function on an event.

This should work.

01local p = script.Parent
02local w = workspace
03local r = w.RedScore
04local b = w.BlueScore
05 
06print"Variables"
07 
08function Touch(hit)
09    if hit.Parent:FindFirstChild("Humanoid")then
10        print"Humanoid"
11        if hit.Parent.TeamColor == BrickColor.new("Bright blue")then
12            r = r + 1
13            elseif
14                hit.Parent.TeamColor == BrickColor.new("Bright red")then
15                    b = b +1
View all 21 lines...
0
He said he does call the function later on in the script. SnowieDev 171 — 5y

Answer this question