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)
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.
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)
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.
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)
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