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)
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?
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 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 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 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!