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

How to fix function not getting called with a condition?

Asked by
R0jym 47
2 years ago

Hello there, I want to call a function only when a specific condition is met which is only when the TeleportPart's BrickColor Value is changed to Maroon, nothing else and just that, however it won't work, I checked the output and there are no errors related to this script (This code is in a LocalScript)

If there is an alternative way to this and still executes the same way I expect which is the function getting called ONLY when the BrickColor Value's changes to a specific color, please provide me the way how so

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CaptureEvent = ReplicatedStorage:WaitForChild("CaptureEvent")
local TeleportPart = game.Workspace.TeleportPart
local value = TeleportPart.BrickColorValue
local plr = game:GetService("Players").LocalPlayer

local function trigger()

    plr.PlayerGui.AllyGui.Button.LocalScript.Disabled = false
    plr.PlayerGui.AllyGui.TeamOnlyGuiScript.Disabled = false
    plr.PlayerGui.CentralGui.Enabled = false
    CaptureEvent:FireServer(TeleportPart)
end

if value.Value == BrickColor.new("Maroon") then
    trigger()
end

Answer this question