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

How do i change a tag name once I touch a brick?

Asked by 8 years ago

I have 2 bricks, one for the red team, and one for the blue team. Once they touch their own team's territory, i have a tag that says that it is touching their brick. Here's the code:

Player = script.Parent
tag = Player:WaitForChild("Team")
tag2 = Player:WaitForChild("IsDominating")
Torso = Player:WaitForChild("Torso")

function CheckIfDominating(Part)
    if tag.Value == ("Bright red") then
        if Part.Name == ("RedTeamControlled") then
            tag2.Value = true
        elseif Part.Name == ("BlueTeamControlled") then 
            tag2.Value = false
        end

    elseif tag.Value == ("Bright blue") then
        if Part.Name == ("RedTeamControlled") then
            tag2.Value = false
        elseif Part.Name == ("BlueTeamControlled") then 
            tag2.Value = true
        end
    end

end
Torso.Touched:connect(CheckIfDominating())

I have no idea whats wrong. When ever i switch bricks it says "attempt to call a nil value". it does not say what is nil. it also says Attempt to connect failed: Passed value is not a function Script 'Workspace.Player1.Checker', Line 23

Thank you

1 answer

Log in to vote
0
Answered by
Uglypoe 557 Donator Moderation Voter
8 years ago

Your problem is on line 23. When you use the :connect() method, you supply it with the name of a function. This means that you don't include the parenthesis that indicate any parameters!

TL;DR: change :connect(CheckIfDominating()) on line 23 to :connect(CheckIfDominating)!

Fixed Code:

Player = script.Parent
tag = Player:WaitForChild("Team")
tag2 = Player:WaitForChild("IsDominating")
Torso = Player:WaitForChild("Torso")

function CheckIfDominating(Part)
    if tag.Value == ("Bright red") then
        if Part.Name == ("RedTeamControlled") then
            tag2.Value = true
        elseif Part.Name == ("BlueTeamControlled") then 
            tag2.Value = false
        end
    elseif tag.Value == ("Bright blue") then
        if Part.Name == ("RedTeamControlled") then
            tag2.Value = false
        elseif Part.Name == ("BlueTeamControlled") then 
            tag2.Value = true
        end
    end

end
Torso.Touched:connect(CheckIfDominating)

If you have any more questions or need help, feel free to ask!

Ad

Answer this question