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

I don't understand why my remote events aren't functioning properly?

The local script is supposed to fire an event which will then be picked up by a server script which will then tween a frame into its position

Local Script: Located in StarterGui

local cd = game.Workspace.shopclick.ClickDetector
local event = game.ReplicatedStorage.OpenShop

cd.MouseClick:Connect(function()
	event:FireServer()
end)

Server Script: Located in StarterGui

local event = game.ReplicatedStorage.OpenShop

event.OnServerEvent:Connect(function(Player)
	
	local frame = script.Parent.Parent.PlayerGui.Main.Shop_UI
	
	frame:TweenPosition(UDim2.new(0.359, 0,0.307, -19), 'Out', 'Back', 1)
	
end)

I get no errors in the output, and I'm wondering if it's because PlayerGui isn't accessible by the client...

It works fine in PlaySolo but I know that disregards FilteringEnabled...

2 comments

1

No, PlayerGui is not accessible by the server. Any GUI coding should NEVER be handled by the server.

0

PlayerGui is accessible by server. ^

2 answers

You can't access things inside of a player's player GUI and have it affect the player from a server script.. It has to be a local script to make changes to the player's client. Whenever testing it's best to test with a test server in studio rather than play solo.

3 comments

0

I tested in solo, saw that it worked and then tested in server

0

It'll work in studio but not in a live game.

0

You can access PlayerGui using server script.

Unfortunately you have your scripts a little backward.

Server scripts can't access PlayerGui, so anything that edits the GUI will have to be done in LocalScripts. Keep in mind you can use RemoteEvents not only to go from client to server, but also vice versa.

ClickDetectors must be handled by server scripts. You could insert one into a part and connect the RemoteEvent that edits the PlayerGui to the MouseClick event.

Edit:

LocalScript

local event = game.ReplicatedStorage.OpenShop
event.OnClientEvent:Connect(function()
	--Tween your frame here
end)

Server Script

local cd = game.Workspace.shopclick.ClickDetector
local event = game.ReplicatedStorage.OpenShop

cd.MouseClick:Connect(function(player)
	event.FireClient(player)
end)

I recommend putting the LocalScript somewhere inside StarterGui so that it gets cloned to PlayerGui when a player's character spawns in and you won't have to reference PlayerGui inside your script. The server script also needs to be inside the part or model that's receiving the click.

2 comments

0

What argument should I use for FireClient?

0

FireClient uses whatever arguments you included in defining the RemoteEvent in the LocalScript, after a required player argument.

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