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

Why does RemoteEvent only work in test mode?

Asked by
Gunzyn 2
6 years ago
Edited 6 years ago

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

0
Test mode runs as though FE was disabled. To test if it works with FE click the start button near the blue test button to see if it works with FE. Viking359 161 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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!

0
Thank you! It works now. Gunzyn 2 — 6y
0
No problem! PyccknnXakep 1225 — 6y
Ad
Log in to vote
-1
Answered by
systack 123
6 years ago

Server scripts should never be located in the playergui! Especially not in FE, it's best to store your server scripts in ServerScriptService!

0
But wouldnt script get removed from ServerScriptService if the game is FE? Gunzyn 2 — 6y
0
I tried putting it somewhere else, but how do I then connect it to the TextButton? I tried """local Button = game.StarterGui.ThrowDice.Frame.Text""" and """local Button = game.Players.LocalPlayer.PlayerGui.ThrowDice.Frame.Text""", but neither worked. Gunzyn 2 — 6y

Answer this question