Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

1
No, PlayerGui is not accessible by the server. Any GUI coding should NEVER be handled by the server. User#19524 175 — 6y
0
PlayerGui is accessible by server. ^ SCP774 191 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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.

0
I tested in solo, saw that it worked and then tested in server VeryDarkDev 47 — 6y
0
It'll work in studio but not in a live game. green271 635 — 6y
0
You can access PlayerGui using server script. SCP774 191 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
What argument should I use for FireClient? VeryDarkDev 47 — 6y
0
FireClient uses whatever arguments you included in defining the RemoteEvent in the LocalScript, after a required player argument. Perthrosama 24 — 6y

Answer this question