Hello, I wanted to know if it was at all possible to fire an event from a server script to a client.
The task I am trying to accomplish is creating an orb that works as a zone and whoever is hit by that zone, gets a script parented to them to which then the server script sends that script that got parented a keyword to make some particle effect appear but for anybody OUTSIDE the zone, there are 0 particle effects.
How would I go about using a remote event that’s Server > Client via hitbox/zone?
Any and all help is appreciated.
My code so that it makes a little more sense:
local VoidZone = Zone.new(Dome)
local DomainLocalScript = game.ReplicatedStorage.Domain.LocalDomainEvent:Clone()
VoidZone.playerEntered:Connect(function(player)
print(player)
DomainLocalScript.Parent = player
task.wait()
DomainEvent:OnClientEvent("Expand")
end)
task.wait(0.1)
VoidZone:Destroy()
print("Zone Deleted")
Once again, thank you if you took the time to read this.
RemoteEvents were literally forged by the gods and placed on this disgusting mortal realm for this purpose, use FireClient() on the server side and listen with OnClientEvent on the client side
EDIT: I’m silly and didn’t read what you were wanting, lol. Just check who is in the zone with something like GetPartBoundsInBox and fire to only those clients (FireClient takes a player parameter)
The best approach in my opinion is not to clone a script to the Client, but rather to have the Client receive a signal using .OnClientEvent within a local script and firing the Client using RemoteEvents located somewhere in ReplicatedStorage.
Then firing the event upon Zone entry from the Server like so:
RemoteEvent:FireClient(player, ...)
Then the Client receives it and performs particle effects upon fired event
RemoteEvent.OnClientEvent:Connect(function()
-- Particle Effects here
end)
The local script belongs within StarterPlayerScripts, but more properly StarterCharacterScripts because the particle effects will ostensibly be shown multiple times (respawning).
You need not do this, but to utilize the Remote Event for multiple functions such as an “effect” event, you may want to tie the event to multiple things, and pass along a string in order to differentiate which effect you would like to use.
When firing clients, make sure to pass in the Player as the first argument.
When firing the Server, the first argument is whatever you pass in.
No, “DomainExpansion” is the “key” I set in the client script so that when it communicates Client > Server, Server knows what to do when it sees “DomainExpansion”
More In depth code
Local:
if input.UserInputType == Enum.UserInputType.MouseButton1 and DomainActive == true and Debounce == false then
Debounce = true
DomainEvent:FireServer("DomainExpansion")
Anim.AnimationId = Activate
local LiveAnim = Character.Humanoid:LoadAnimation(Anim)
LiveAnim:Play()
task.wait(10)
Debounce = false
end
end)
Server:
DomainEvent.OnServerEvent:Connect(function(Player, Key)
if Key == "DomainExpansion" then