Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalScript can't find bool value in the player?

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

✓ Accepted answer

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.

2 comments

0

Ok, thank you, also its in a loop so that it keeps checking (is there another way to do that?).

This discussion is preserved as it was. New answers, comments, and votes are closed.