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

Having issues with disabled property in a local script?

I am making a script for my game that shows a GUI to each individual player after a certain condition is met. Here is the relevant code that I am having trouble with:

This first block of code comes from a server script which accesses ServerStorage and finds the relevant GUI that I want to display. Its purpose is to enable a local script in StarterPlayerScripts.

local gameStatus = script.Parent.GameStatus
local roleGUI = game.StarterGui.GUIs.RoleGUI


while wait(1) do
	
	while gameStatus.Value == "Starting" do
		
		print("Game started!")
		game.StarterPlayer.StarterPlayerScripts.Role.Disabled = false
		wait(1)
		
	end	
	
end

...And here is the code from the local script.

print("Working!")
local roleGUI = game.StarterGui.GUIs.RoleGUI:Clone()
roleGUI.Frame.Visible = true
roleGUI.Parent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

I have tested this before in Play Solo mode (I'm aware that solo mode and start server are two different things; I don't think this is the problem here) with the disabled property off and everything works fine. However, whenever I manually toggle the disabled property on, the code doesn't run and the case doesn't seem to be the same when I attempt to this with start server mode.

Could somebody please help me understand what is causing the problem?

1 answer

Try this:

game.Players.PlayerAdded:connect(function(player)
repeat wait() until player:WaitForChild("PlayerGui")

local gameStatus = script.Parent.GameStatus
local roleGUI = player.PlayerGui.GUIs.RoleGUI --You can't refer StarterGui.


while wait(1) do

    while gameStatus.Value == "Starting" do

        print("Game started!")
	repeat wait() until game.StarterPlayer.StarterPlayerScripts.LSenabled
        game.StarterPlayer.StarterPlayerScripts.LSenabled.Value = true
        wait(1)

    end 

end

Local Script:

--Create the bool that will determine 
local boolValue = Instance.new("BoolValue")
boolValue.Parent = script.Parent
boolValue.Name = "LSenabled"

while wait() do
	if script.Parent.LSenabled.Value == true then
		print("Working!")
		local roleGUI = game.StarterGui.GUIs.RoleGUI:Clone()
		roleGUI.Frame.Visible = true
		roleGUI.Parent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
	end
end

What we did here was creating a bool value, that would determine when the Local Script should be "triggered"

If this works, mark as answer, please!

As always, good scripting!

3 comments

0

ServerScriptService.GameState.Starting:1: attempt to index field 'LocalPlayer' (a nil value) - this was returned by the server script.

0

Done, I edited my answer, sorry for that error, but I already fixed it. Try again!

0

ServerScriptService.GameState.Starting:20: 'end' expected (to close 'function' at line 1) near '' - where is end supposed to close the function?

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