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

Why does this RemoteEvent script only work in studio? [Answered]

Asked by 8 years ago

I am new to RemoteEvent's and experimenting with them trying to figure out how to use them and such, I thought I got it to work but it only works in studio.

Script to fire it(running it in the Command Bar):

game.Workspace.Model.Events.RemoteEvent:FireAllClients()

Script for when it's fired(inside the RemoteEvent, in a ServerScript):

-- Variables
local Model = script.Parent.Parent

local Enabled = false
local WaitTime = 1 -- In seconds

-- Main script
script.Parent.OnClientEvent:connect(function()
    Enabled = not Enabled
    repeat
        if not Enabled then
            return false
        end
        print("Test worked.")
        wait(WaitTime)
    until not Enabled
end)

That script errors OnClientEvent can only be used on the client, so I tried converting it to OnServerEvent and FireServer() in the Command Bar and that worked, but then when I put it in a ScreenGui, TextButton, Scriptwith the same firing script it gave this error: FireServer can only be called from the client.

Other script to fire it(in Command Bar & TextButton):

game.Workspace.Model.Events.RemoteEvent:FireServer()

Other script for when it's fired(Same directory as other, inside the RemoteEvent in aServerScript):

-- Variables
local Model = script.Parent.Parent

local Enabled = false
local WaitTime = 1 -- In seconds

-- Main script
script.Parent.OnServerEvent:connect(function()
    Enabled = not Enabled
    repeat
        if not Enabled then
            return false
        end
        print("Test worked.")
        wait(WaitTime)
    until not Enabled
end)

Any idea's on how I can get it to work properly? Any help appreciated.

0
Basically if you use OnServerEvent then you have to use that event from the server and call FireServer from a local script. If you use OnClientEvent you have to use it from a local script and call FireClient from a server script. fishguy100 135 — 8y
0
Thanks. :D ISellCows 2 — 8y
0
don't answer questions in comments User#11893 186 — 8y

Answer this question