Starflyer
Starflyer

Reputation: 53

Roblox if Statement not running

I was wondering if I could get some help with this small script I tested. For some reason, the if statement isn't executing, meaning the function won't run even if the value doesn't equal Rinzler. charData is a StringValue to be specific.

local charData = script.Parent.Data.CharacterData
local active = game.Workspace.Part

function change()
    if not charData.Value == "Rinzler" then
        charData.Value = "Rinzler"
        print("Character has changed to Rinzler.")
    end
end

active.Touched:Connect(change)

"Character has changed to Rinzler" isn't printing in the console no matter what I do.

Upvotes: 1

Views: 308

Answers (1)

Vlad
Vlad

Reputation: 5857

The problem is here if not charData.Value == "Rinzler"

The not operator has higher priority than == in operator precedence list. Update that code to:

function change()
    if charData.Value ~= "Rinzler" then
        charData.Value = "Rinzler"
        print("Character has changed to Rinzler.")
    end
end

Upvotes: 2

Related Questions