Attribute not updating, even when changed client-side and server side

The code below is inside StarterCharacterScripts and is supposed to run upon spawning in. However, ‘guiState’ wouldn’t be updating no matter what. I have tried updating client and server-side, however if i change it, it still wouldn’t update. Can anyone help?

local player = game.Players.LocalPlayer

local playerGUI = player:WaitForChild("PlayerGui")

playerGUI.ScreenOrientation = Enum.ScreenOrientation.LandscapeRight

local guiState = player.PlayerGui.MainMenu:GetAttribute("State")

playerGUI:WaitForChild("AbilityButton").Enabled = false
playerGUI:WaitForChild("Level").Enabled = false
playerGUI:WaitForChild("Map").Enabled = false
playerGUI:WaitForChild("MainMenu").Enabled = false
playerGUI:WaitForChild("WeaponSelection").Enabled = false

playerGUI:WaitForChild(guiState).Enabled = true

player.CharacterAdded:Connect(function()
	playerGUI:WaitForChild("AbilityButton").Enabled = false
	playerGUI:WaitForChild("Level").Enabled = false
	playerGUI:WaitForChild("Map").Enabled = false
	playerGUI:WaitForChild("MainMenu").Enabled = false
	playerGUI:WaitForChild("WeaponSelection").Enabled = false

	playerGUI:WaitForChild(guiState).Enabled = true
end)

game.Workspace.ChosenMusic:GetAttributeChangedSignal("musicState"):Connect(function()
	local musicName = game.Workspace.ChosenMusic:GetAttribute("Music")
	local playingMusic = game.Workspace.ChosenMusic:FindFirstChild(musicName)
	
	if game.Workspace.ChosenMusic:GetAttribute("musicState") == false then
		playingMusic.Volume = 0
		
		playingMusic:Stop()
	end
end)
3 Likes

Hello, which attribute is not changing?

player.PlayerGui.MainMenu:GetAttribute(“State”)

You’re supposed to use :SetAttribute() when changing the value of one.

Yeah that’s true, by the way I dont see any attribute changed on this script, :SetAttribute() works for creating and updating an attribute. Ej: player.PlayerGui.MainMenu:SetAttribute(“State”, “YourValue”). (or number whatever you got), if that isnt your problem, then what is it?

I know. I am trying to add a main menu, and whenever you click this button, it should change the attribute (Do note: the following is a local script)

local button = script.Parent
local mainMenu = script.Parent.Parent.Parent

local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	mainMenu.Enabled = false
	player.PlayerGui.WeaponSelection.Enabled = true
	
	mainMenu:SetAttribute("State", "WeaponSelection")
end)

However, the original script will not update states.

Is the script in the original post is a server script?

It’s a local script, inside PlayerCharacterScripts

You could use the output console and check whats wrong, ej:

game.Workspace.ChosenMusic:GetAttributeChangedSignal("musicState"):Connect(function()
	local musicName = game.Workspace.ChosenMusic:GetAttribute("Music")
	local playingMusic = game.Workspace.ChosenMusic:FindFirstChild(musicName)
print("Attribute detected changed")-----------------------------
	if game.Workspace.ChosenMusic:GetAttribute("musicState") == false then
		playingMusic.Volume = 0

		playingMusic:Stop()
	end
end)

also

local button = script.Parent
local mainMenu = script.Parent.Parent.Parent

local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
	mainMenu.Enabled = false
	player.PlayerGui.WeaponSelection.Enabled = true

	mainMenu:SetAttribute("State", "WeaponSelection")
	print("attributed changed from button")
end)

I have tried this earlier. It says the original script is still “MainMenu”, but button says it is “WeaponSelection”

What do you mean with

“It says the original script is still “MainMenu””

local guiState = player.PlayerGui.MainMenu:GetAttribute("State")
print(guiState)

The printed string is “MainMenu”

I recommend you to go into play and test it, get into the attribute and check if when you press it it changes. Important: Check this line local mainMenu = script.Parent.Parent.Parent,

I’ve checked already. The attribute has changed. I tried changing the code abit to this, but still same outcome.

local button = script.Parent
local player = game.Players.LocalPlayer

local mainMenu = player.PlayerGui.MainMenu

button.MouseButton1Click:Connect(function()
	mainMenu.Enabled = false
	player.PlayerGui.WeaponSelection.Enabled = true
	
	mainMenu:SetAttribute("State", "WeaponSelection")
end)

I think the problem is that it only changes on the client, i know the other script is also on the client but I dont trust it, you could try using a remote event.

Button Script=

local button = script.Parent
local player = game.Players.LocalPlayer

local mainMenu = player.PlayerGui.MainMenu
local event = game:GetService("ReplicatedStorage").Event
button.MouseButton1Click:Connect(function()
	mainMenu.Enabled = false
	player.PlayerGui.WeaponSelection.Enabled = true
	
	event:FireServer("WeaponSelection")
end)

Server=

local event = game:GetSevice......
local mainMenu = player.PlayerGui.MainMenu
event.OnServerEvent:Connect(function(player,weaponselectec)
	mainMenu:SetAttribute("State", weaponselectec)
end)

thats just an example, i dont really think PlayerGui works in server scripts

I’ve already tried a remoteEvent, even stated in the title. It still ahsn’t worked.

I have no idea why, but this problem was fixed as soon as I put the script inside of StarterPlayerScripts instead of StarterCharacterScripts, but now the problem is fixed!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.