How would I only show a gui to a player if they have a value?

What do you want to achieve?

I want to only show a GUI to a player if they have a value inside their character.
I am happy to explain more clearly if you don’t understand what I mean.

normal script in serverscriptservice:
I get no errors, the gui just doesn’t show up.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local gui = player.PlayerGui:WaitForChild("Sacrifce").MagicBack
		local order = player.Character:FindFirstChild("Order")
		local orderwolf = player.Character:FindFirstChild("OrderWolf")

		if order or orderwolf then
			gui.Visible = true
			
			
		end
	end)
end)
2 Likes

Try to do some printing on the if statement. Maybe it doesn’t meet the requirements on it

1 Like

Quick questionnaire:

  1. What type or values are order and orderwolf?
  2. Did you try checking the position of the gui?
  3. most important, I don’t really think changing the gui values on the server would affect it’s values on the client (i.e the gui is visible on the server, but the client, a.k.a the player won’t be able to see their own gui), so you need to use a remote event for indicating the client to activate the gui from the client-side.
1 Like
  1. they’re string values, but im just focusing on the NAME of the value so i dont see why it would matter what type they are

  2. yes, the gui is positioned fine

  3. i will try a remote event

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local gui = player.PlayerGui:WaitForChild("Sacrifce").MagicBack
		local order = char:FindFirstChild("Order")
		local orderwolf = char:FindFirstChild("OrderWolf")

		if order or orderwolf then
			gui.Visible = true
			
			
		end
	end)
end)
1 Like

I printed “can see gui” if they have the value, and it printed.
image

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local gui = player.PlayerGui:WaitForChild("Sacrifce").MagicBack
		local order = char:FindFirstChild("Order")
		local orderwolf = char:FindFirstChild("OrderWolf")

		if order or orderwolf then
            player.PlayerGui:WaitForChild("Sacrifce").Enabled = true
			gui.Visible = true
			
			
		end
	end)
end)

there’s no need to enable the gui or anything, i figured out it does show however my character respawns to change character, so the gui is set back to not visible. do you know how i could avoid this? I tried a wait and it didn’t work.

Try this

game.Players.PlayerAdded:Connect(function(player)
     local char = player.Character
     	local gui = player.PlayerGui:WaitForChild("Sacrifce").MagicBack
		local order = char:FindFirstChild("Order")
		local orderwolf = char:FindFirstChild("OrderWolf")

		if order or orderwolf then
            player.PlayerGui:WaitForChild("Sacrifce").Enabled = true
			gui.Visible = true
		end
	player.CharacterAdded:Connect(function(char)
		local gui = player.PlayerGui:WaitForChild("Sacrifce").MagicBack
		local order = char:FindFirstChild("Order")
		local orderwolf = char:FindFirstChild("OrderWolf")

		if order or orderwolf then
            player.PlayerGui:WaitForChild("Sacrifce").Enabled = true
			gui.Visible = true
		end
	end)
end)

Sooo, the possible solution as of now is, creating a “RemoteEvent” under replicated storage and using that to fire an event for the clientele

Server Script under the serverscriptservice:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local gui = player.PlayerGui:WaitForChild("Sacrifce").MagicBack
		local order = player.Character:FindFirstChild("Order")
		local orderwolf = player.Character:FindFirstChild("OrderWolf")

		if order or orderwolf then
			game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireClient(player, 1) --use the second parameter as 1 or 0 for turning the gui on and off
else 
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireClient(player, 0)
		end
	end)
end)

And the localscript under StarterPlayerScripts would be:

local gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Sacrifce").MagicBack
game.ReplicatedStorage:WaitForChild("RemoteEvent").onClientEvent:Connect(function(val)
if val == 1 then
gui.visible = true
else
gui.visible = false
end)
1 Like

this doesn’t work unfortunately

Just a silly question but need to ask… are you spelling Sacrifice incorrectly or is that how you spell your object name?

2 Likes

Are you getting any particular errors by any chance?

Also double check the values of the object names I’ve typed, since I guess there could possibly be a typo in my coding

Thank you to everyone who has helped, I have just put a localscript in StarterCharacterScripts, the script is here incase anyone needs it.

local player = game.Players.LocalPlayer
local pgui = player.PlayerGui
local frame = pgui.Sacrifce.MagicBack
local order = player.Character:FindFirstChild("Order")
local orderwolf = player.Character:FindFirstChild("OrderWolf")

if order or orderwolf then
	frame.Visible = true
end
3 Likes

frame.Visible = (order or orderwolf)
If you prefer single line expressions.

1 Like