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

How To Enable A PlayerGui FE?

Hello! So I have a GUI and I want it to be enabled when a player clicks something. When I run this though, on line 21, I get an issue saying the GUI is not valid. Upon seeing this issue, I looked into the hierarchy of and I cannot find where any of the GUIs are. I am using filtering enabled so how can I get the GUI to become enabled?

The rest of the script works so no need to worry.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local landPurchaseEvent = Instance.new("RemoteEvent")
landPurchaseEvent.Name = "LandPurchased"
landPurchaseEvent.Parent = ReplicatedStorage

local event = game:GetService("ReplicatedStorage").LandPurchased
local price = 700
local land = game.Workspace.Land1

local function onEvent(player,money)
	if player.leaderstats.Money.Value > price - 1 and player.PlayerOwnsLand.Value == false then
    player.leaderstats.Money.Value = player.leaderstats.Money.Value - price -- Assuming it's leadersats in the player
	land.Owner.Value = player.Name
	land.ForSaleSign.Click.SurfaceGui.Price.Text = ("OWNED BY: "..player.Name)
	player.PlayerOwnsLand.Value = true
	--land.Sell.Position = Vector3.new(land.Sign.Click.Position.X,land.Sign.Click.Position.Y,land.Sign.Click.Position.Z)
	land.ForSaleSign.Click.Script.Disabled = true
	print("Purchased")
	--
	local list = player.PlayerGui.HouseOptionsPlot1
	list.Enabled = true
	--
	else
		print("Purchasing Error")
	end
end

event.OnServerEvent:Connect(onEvent)

1 comment

0

In FE, the Server doesn't have access to the PlayerGUI or at least the StarterGUIs that are added to the player. I would just send a RemoteEvent to the client to enable the GUI.

1 answer

✓ Accepted answer

The only way you'll be able to define a Clients guis in a Server Script in Filtering Enabled is using a remote function. Because of this, it would be easier to just have a OnClientEvent in a local script in player guis, like already commented by PreciseLogic.

By using a Remote Function, you can call a players client and have it return what you want to you server script. All you need is a way of defining Player in your ServerScript. You would do something like this:

--In Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local landPurchaseEvent = Instance.new("RemoteFunction") --Notice this is remote function and not event
landPurchaseEvent.Name = "LandPurchased"
landPurchaseEvent.Parent = ReplicatedStorage

game:GetService("Players").PlayerAdded:connect(function(player)
	local gui = landPurchaseEvent:InvokeClient(player)  --This will return the gui from the RequestedPurchaseEvent in your local script, you can now edit gui from here
end)


--In Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local landPurchaseEvent = ReplicatedStorage:WaitForChild("LandPurchased")
local gui = DEFINEGUIHERE

local function RequestedPurchaseEvent()
	return gui
end

landPurchaseEvent.OnClientInvoke = RequestedPurchaseEvent

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