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

Why does this only work in studio?

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)

4 comments

0

I had a problem like this when I was using remote events, I never fixed it...

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.

0

output

0

Output please?

1 answer

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!

1 comment

0

Still only work's in studio. :l

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