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, Script
with 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.