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

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

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. :)

8 comments

0

Are there BrickColor values inside the character? Or are you using roblox's classic team system?

0

The classic system.

0

Alright.

0

Are the RedScore and BlueScore values? Like Number or Int Values?

0

Yes. IntValues.

0

Alright.

0

What's the name of the Blue and Red team inside the explorer panel?

0

Blue and Red.

2 answers

✓ Accepted answer

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 

2 comments

0

Sorry, doesn't work.

1

Never mind, I did some tweaking and now it works! Thanks!

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)

1 comment

0

He said he does call the function later on in the script.

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