Hello! I'm trying to use RemoteEvent to clone something infront of the player when he clicks the Gui's TextButton, but for some reason it only works in test mode.
First of all, here is my explorer: Screenshot
RemoteEvent, Script and LocalScript are marked.
Here is my LocalScript:
ThrowEvent = game.ReplicatedStorage:WaitForChild("ThrowEvent") script.Parent.MouseButton1Click:connect(function() ThrowEvent:FireServer() end)
And server Script:
ThrowEvent = game.ReplicatedStorage:WaitForChild("ThrowEvent") ThrowEvent.OnServerEvent:connect(function() print("Event fired") --Part that isn't important end)
When I saw it only works in test mode, I tried only printing "Event fired", but that also didn't work in a server, so i'm guessing there's nothing wrong with other part of the script.
Does anybody have any idea what could be wrong? I tried similar script in another game, everything is same except it's about players moving to a part, when someone says "MoveTo" and it worked in both, test mode and the server (original concept was to only move player that says it, which I could easily fix, but I don't care about that, it was just a test).
The problem was that your script needed to be in a LocalScript
.For Example:
Server Script:
local re = game:GetService("ReplicatedStorage").RemoteEvent re.OnServerEvent:Connect(function() print("Event fired") end)
Local Script:
script.Parent.TextButton.MouseButton1Click:Connect(function() local re = game:GetService("ReplicatedStorage").RemoteEvent --It's always best to store remote events in the replicated storage re:FireServer() end)
Hierarchy here. Please accept my answer if this helped!
Server scripts should never be located in the playergui! Especially not in FE, it's best to store your server scripts in ServerScriptService!