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

script ignores my if statement?

Asked by
mehssi 20
9 years ago

this script is only suppose to work if player is in team Red or Red2, however it still works if you're not on either team, anyone know why?

01red = BrickColor.new("21")
02red2 = BrickColor.new("1004")
03function T(hit)
04if (hit.Name == "SoccerBall") then
05local plyr = game.Players:FindFirstChild(hit.Kicker.Value)
06if plyr.TeamColor == red or red2 then
07plyr.leaderstats.Overall.Value = plyr.leaderstats.Overall.Value + 0.04
08plyr.hiddenstats.Goals.Value = plyr.hiddenstats.Goals.Value + 1
09plyr.Pointz.Points.Value = plyr.Pointz.Points.Value + 1
10hit.Position = script.Parent.Parent.Parent.Cage.CageFloor.Position + Vector3.new(0, 1.7, 0)
11p = script.Parent.Parent.Parent.Cage:GetChildren()
12for i = 1, #p do
13p[i].BrickColor = red
14end
15wait(35)
View all 24 lines...

2 answers

Log in to vote
2
Answered by 9 years ago

Next time, please code block your code. I've noticed what was wrong. In your if statement you put if plyr.TeamColor == red or red2 then this would check if the player's team color is equal to red or if red2 exists so returns true. You need to change it to if plyr.TeamColor == red or plyr.TeamColor == red2 then so then it checks if the team color is either of the 2. Here's what the code should be:

01red = BrickColor.new("21")
02red2 = BrickColor.new("1004")
03 
04function T(hit)
05    if (hit.Name == "SoccerBall") then
06        local plyr = game.Players:FindFirstChild(hit.Kicker.Value)
07        if plyr.TeamColor == red or plyr.TeamColor == red2 then
08            plyr.leaderstats.Overall.Value = plyr.leaderstats.Overall.Value + 0.04
09            plyr.hiddenstats.Goals.Value = plyr.hiddenstats.Goals.Value + 1
10            plyr.Pointz.Points.Value = plyr.Pointz.Points.Value + 1
11            hit.Position = script.Parent.Parent.Parent.Cage.CageFloor.Position + Vector3.new(0, 1.7, 0)
12            p = script.Parent.Parent.Parent.Cage:GetChildren()
13            for i = 1, #p do
14                p[i].BrickColor = red
15            end
View all 26 lines...
Ad
Log in to vote
1
Answered by 9 years ago

Well, you need to define red and red2 not with numbers, becuase it is a BrickColor, eg

01red = BrickColor.new("Red")
02red2 = BrickColor.new("1004")--Change to name of the Color, not the number.
03function T(hit)
04if (hit.Name == "SoccerBall") then
05local plyr = game.Players:FindFirstChild(hit.Kicker.Value)
06if plyr.TeamColor == red or red2 then
07plyr.leaderstats.Overall.Value = plyr.leaderstats.Overall.Value + 0.04
08plyr.hiddenstats.Goals.Value = plyr.hiddenstats.Goals.Value + 1
09plyr.Pointz.Points.Value = plyr.Pointz.Points.Value + 1
10hit.Position = script.Parent.Parent.Parent.Cage.CageFloor.Position + Vector3.new(0, 1.7, 0)
11p = script.Parent.Parent.Parent.Cage:GetChildren()
12for i = 1, #p do
13p[i].BrickColor = red
14end
15wait(35)
View all 24 lines...

Hope this helps!

0
Don't think that's the correct answer... General_Scripter 425 — 9y

Answer this question