How to make scripts work on server instead of client?

I have a set of LocalScripts in the StarterGui folder, which is made to enable a ParticleEmitter when a certain key is pressed.
However, it only shows the particles on the client and not the entire server.

Here is the script:

local userInputService = game:GetService("UserInputService")
local particle = game.Workspace.Fountains.FountainB.cannon.particleCore.fountain

userInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.B then
		particle.Enabled = true
	end
end)

userInputService.InputEnded:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.B then
		particle.Enabled = false
	end
end)

Anyway to make this script work for the entire server?

By using a local/client script, you are turning on a particle, then you are only turning it on for the client… That change in client will never replicate to server.
Do a remote:FireServer() to tell the client wants to enable a particle, on server side turn on the particle, all players will be able to see the particle

Should anything go in the “()” specifically for a particle? Or no

Yup, you should send the reference of the particle or part the player wants to enable, you send that to server by the remote remote:FireServer(thePartcileToEnable)

Server should look for that particle, or even have a list to decide if that player or that particle is allowed to be turned on, then turn it on

If a bunch of particles has the same name, will it enable all of them?

I’m saying this because each LocalScript ties to each ParticleEmitter, in which all of them are named “fountain”

So, putting remote:FireServer(fountain) would work?

1 Like

If you send the .Name property of the particle then search inside the particles with the same name, of course that wont work.

If you are sending the instance, and you already have a server list of the instances, then it will be pretty easy to find the right particle player “clicked”

If I wanted to change “particle.Enabled = true” into a remove event, do I put that line of text into the parentheses?

Look this example:

You have many parts, each part has a particle emitter and a click detector, all those parts are in a folder called “ParticlesToClick”.

Then you have one client script in StarterCharacterScripts connecting all those parts to one function:

local TheRemote = game.ReplicatedStorage:WaitForChild("EnableParticleRemote")

for _, p in pairs(game.Workspace:WaitForChild("ParticlesToClick"):GetChildren()) do
	p.ClickDetector.MouseClick:Connect(function()
		warn("ouch")
		TheRemote:FireServer(p.ParticleEmitter)
	end)
end

When any player with that client script, clicks any of those parts inside the ParticlesToClick folder, a function will run, firing a remote to tell the server which part and which player clicked.
The remote call will be listened by this server script, in ServerScriptService, to enable that specific particle:

local TheRemote = game.ReplicatedStorage:WaitForChild("EnableParticleRemote")

TheRemote.OnServerEvent:Connect(function(player, particle)
    particle.Enabled = true
end)

For more detail, I’ll show the things I have.


These are the models in the workspace, which contain the particles.

These are all the LocalScripts tied to each particle. (the folders have local scripts too)

Well first, I suggest that you dont need one script per key to push, you should connect them all in one client script that controls the keybinds

For now, I’m keeping them separated, since there are a lot of scripts.
I also keep a lot in folders since I have problems keeping track, so organizing helps with it.

Theres no better organizing than scripts keeping track of things in map and things behind curtains…

Just grab your folder that contains all the clickable parts with particles and connect them to one function, to call the remote and make server to turn that one, its pretty simple

If you mean you want it to enable and disable so everyone can see the changes in particles, you can’t use the ```UserInputService`` server side because of it being a “User Input” meaning that it works locally only. You could however use a remote event to fire up to the client when the input is activated.

1 Like