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?

red = BrickColor.new("21")
red2 = BrickColor.new("1004")
function T(hit)
if (hit.Name == "SoccerBall") then
local plyr = game.Players:FindFirstChild(hit.Kicker.Value)
if plyr.TeamColor == red or red2 then
plyr.leaderstats.Overall.Value = plyr.leaderstats.Overall.Value + 0.04
plyr.hiddenstats.Goals.Value = plyr.hiddenstats.Goals.Value + 1
plyr.Pointz.Points.Value = plyr.Pointz.Points.Value + 1
hit.Position = script.Parent.Parent.Parent.Cage.CageFloor.Position + Vector3.new(0, 1.7, 0) 
p = script.Parent.Parent.Parent.Cage:GetChildren()
for i = 1, #p do
p[i].BrickColor = red
end
wait(35)
workspace.whistle1:Play()
script.Parent.Parent.Parent.SoccerBall.Position = script.Parent.Parent.Parent.Pad.Position + Vector3.new(0, 1.7, 0)
for n = 1, #p do
p[n].BrickColor = BrickColor.new("194")
end
end
end
end
script.Parent.Touched:connect(T)

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:

red = BrickColor.new("21")
red2 = BrickColor.new("1004")

function T(hit)
    if (hit.Name == "SoccerBall") then
        local plyr = game.Players:FindFirstChild(hit.Kicker.Value)
        if plyr.TeamColor == red or plyr.TeamColor == red2 then
            plyr.leaderstats.Overall.Value = plyr.leaderstats.Overall.Value + 0.04
            plyr.hiddenstats.Goals.Value = plyr.hiddenstats.Goals.Value + 1
            plyr.Pointz.Points.Value = plyr.Pointz.Points.Value + 1
            hit.Position = script.Parent.Parent.Parent.Cage.CageFloor.Position + Vector3.new(0, 1.7, 0) 
            p = script.Parent.Parent.Parent.Cage:GetChildren()
            for i = 1, #p do
                p[i].BrickColor = red
            end
            wait(35)
            workspace.whistle1:Play()
            script.Parent.Parent.Parent.SoccerBall.Position = script.Parent.Parent.Parent.Pad.Position + Vector3.new(0, 1.7, 0)
            for n = 1, #p do
                p[n].BrickColor = BrickColor.new("194")
            end
        end
    end
end

script.Parent.Touched:connect(T)
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

red = BrickColor.new("Red")
red2 = BrickColor.new("1004")--Change to name of the Color, not the number.
function T(hit)
if (hit.Name == "SoccerBall") then
local plyr = game.Players:FindFirstChild(hit.Kicker.Value)
if plyr.TeamColor == red or red2 then
plyr.leaderstats.Overall.Value = plyr.leaderstats.Overall.Value + 0.04
plyr.hiddenstats.Goals.Value = plyr.hiddenstats.Goals.Value + 1
plyr.Pointz.Points.Value = plyr.Pointz.Points.Value + 1
hit.Position = script.Parent.Parent.Parent.Cage.CageFloor.Position + Vector3.new(0, 1.7, 0) 
p = script.Parent.Parent.Parent.Cage:GetChildren()
for i = 1, #p do
p[i].BrickColor = red
end
wait(35)
workspace.whistle1:Play()
script.Parent.Parent.Parent.SoccerBall.Position = script.Parent.Parent.Parent.Pad.Position + Vector3.new(0, 1.7, 0)
for n = 1, #p do
p[n].BrickColor = BrickColor.new("194")
end
end
end
end
script.Parent.Touched:connect(T)

Hope this helps!

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

Answer this question