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

LocalScript can't find bool value in the player?

Asked by 7 years ago

Okay, so I made a script that would create a bool value to check if the game intro is ran. Here is the script for that:

game.Players.PlayerAdded:connect(function(player)
    local IntroRan = Instance.new('BoolValue', player)
    IntroRan.Name = 'IntroRan'
    IntroRan = false
end)

So I checked the location when I went into play mode, and I saw the Boolvalue where it should be (Players.LocalPlayer). I also created local script to check if the bool value is true or not, and if it is, it will enable a script. Here is the script for that:

local player = game.Players.LocalPlayer
local introran = player.IntroRan
while true do
    wait(0.05)
if introran == true then
    player.PlayerGui.Warning.LocalScript.Disabled = false
end
end

It looks like the scripts should work but it doesn't. In the script output, it says that the bool is not a valid member of player. What's wrong?

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

Most likely, the LocalScript is running before the event listener function to PlayerAdded does. So, when the LocalScript runs, IntroRan doesn't exist. This can be remedied by using WaitForChild:

local player = game.Players.LocalPlayer
local introran = player:WaitForChild('IntroRan') --// This will yield the script until IntroRan exists.
while true do
    wait(0.05)
    if introran then
        player.PlayerGui.Warning.LocalScript.Disabled = false
    end
end

Also, I'm not entirely sure why you're using a while loop there; it would probably be best to omit it entirely.

Hope this helped.

PS: See how much easier it is to read your code when it's properly indented? I fixed it for you this time, but please properly indent your code in the future.

0
Ok, thank you, also its in a loop so that it keeps checking (is there another way to do that?). flufffybuns 89 — 7y
Ad

Answer this question