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

Local script will not change Boolean Value?

Asked by 4 years ago
Edited 4 years ago

I have a local script and a boolean value in StarterGui. This local script should change the value in folder at line 11, although for some reason it will not. Does it have anything to do with being a local script?

local part = workspace:WaitForChild("ActivateBurgerJob")
local plr = game.Players.LocalPlayer;
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
local ui = script.Parent;
canSeeGui = script.Parent.Parent:WaitForChild("canSeeGui").Value

local function onTouch(hit)
    if plr.Character ~= nil and hit.Parent == plr.Character and canSeeGui == true then
        wait(0.2)
        canSeeGui = false
        Controls:Disable()
        ui.Enabled = true
        print("Contrls disbaled")      
    end 

end


part.Touched:Connect(onTouch)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

While it is true that anything the local script does will not be reflected on the Server, if you're working just in local GUI, other local scripts will be able to read the value just fine. The real issue here is likely this:

canSeeGui = script.Parent.Parent:WaitForChild("canSeeGui").Value

Specifically, the .Value part of it. When you define a variable as the .Value, you're not actually defining it as the object & it's value, you're defining it as the actual literal value.

So assuming CanSeeGUI is a BoolValue, you're defining CanSeeGUI's variable as "True" rather than the BoolValue's current value. So when you set it to False, you're not actually changing the Bool Value, you're just making the local variable to False.

To fix just, just remove the .Value part, and add it in when you change it.

For instance, CanSeeGui.Value = false, rather than CanSeeGui = false.

This is a fairly common mistake even some elder programmers forget from time to time.

1
Thank you this actually fixed everything, I've been going in circles trying to fix this for hours yet I didn't realize it was this small of a fix haha FizzyFlame 42 — 4y
0
No problem! Glad I could help :) Maxwell_Edison 105 — 4y
Ad

Answer this question