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

Why does this only work in studio?

Asked by 9 years ago

I am new to RemoteEvent's and trying to experiment how to use them, can someone tell me why this script work's in Studio but not in a actual game server, and tell me how to fix it?

Script to fire it:

local plr = script.Parent.Parent.Parent.Parent

local event = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Click:connect(function(plr)
    event:FireServer()
end)

Script for when it's fired:

local event = game.ReplicatedStorage.RemoteEvent

event.OnServerEvent:connect(function(args)
    local m = Instance.new("Message",workspace)
    m.Text = math.random(100,999)
end)
0
I had a problem like this when I was using remote events, I never fixed it... General_Scripter 425 — 9y
0
Try using `WaitForChild()` for the event assignment. Remember that a server takes a little bit to load objects. If that works let me know and I will post it as the answer. Necrorave 560 — 9y
0
output 1waffle1 2908 — 9y
0
Output please? Shawnyg 4330 — 9y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

In the ServerSided script, line 3. Remove the parameter args. Since you never put any arguments/parameters when you FireServer(), you don't need any parameters there. Also, the script to fire it. Line 5, remove the parameter plr. So:

Script to fire:

local event = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Click:connect(function()
    event:FireServer()
end)

OnServerEvent:

local event = game.ReplicatedStorage.RemoteEvent

event.OnServerEvent:connect(function()
    local m = Instance.new("Message",workspace)
    m.Text = tostring(math.random(100,999)) -- Just to be safe, use tostring.
end)

Hope I helped! Any further questions/comments/errors? Be sure to comment!

0
Still only work's in studio. :l ISellCows 2 — 9y
Ad

Answer this question