Making script use remote events

I have a script that doesn’t show particles to other players when it emits, using a certain key to activate.

local userInputService = game:GetService("UserInputService")
local particles = game.Workspace.Fountains.FlameK1.cannon.particleCore

function emit()
	for number,index in pairs(particles:GetChildren()) do
		if index:IsA("ParticleEmitter") then
			index.Enabled = not index.Enabled
		end
	end
end

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

	if input.KeyCode == Enum.KeyCode.K then
		emit()
	end

end)

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

	if input.KeyCode == Enum.KeyCode.K then
		emit()
	end

end)

Is there any way to implement remote events into this script? (or any way to make it go to the server)

Just move the emit function onto a server script and replace the emit function on the localscript with RemoteEvent:FireServer()

The localscript would look something like:

local userInputService = game:GetService("UserInputService")
local remote = your.remote
userInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.K then
		remote:FireServer()
	end

end)

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

	if input.KeyCode == Enum.KeyCode.K then
		remote:FireServer()
	end

end)

And for the server script it would look something like

local particles = your.particle

your.remote.OnServerEvent:Connect(function()
    for number,index in pairs(particles:GetChildren()) do
	    if index:IsA("ParticleEmitter") then
            index.Enabled = not index.Enabled
	    end
    end
end)
1 Like

My version is alot cleaner. Try this

The local script:

local UserInputService = game:GetService("UserInputService")
local ParticleEvent = your.remote.event
UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.K then
		ParticleEvent:FireServer()
	end

end)

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

	if input.KeyCode == Enum.KeyCode.K then
		ParticleEvent:FireServer()
	end

end)

Server script:

local Particles = game.Workspace.Fountains.FlameK1.cannon.particleCore

your.remote.event.OnServerEvent:Connect(function()
    for number,index in pairs(particles:GetChildren() do
	    if index:IsA("ParticleEmitter") then
            index.Enabled = not index.Enabled
	    end
    end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.