Is this script client-sided or server-sided? (needs fixing)

I got this script sorted out, but I have another issue I want to address

Is this script server-sided or client-sided?

(The goal of this script is to change the speed of multiple particles using a SliderGui, which I have set up. I want it to be server-sided so others can see the change in speed while keeping the slider only on my screen)

-- Static variables

-- -- UI-related
local slider : GuiObject = script.Parent.Bar
local knob : TextButton = slider:FindFirstChild("Knob") :: TextButton
local previousSliderValue = 0
local sliderValue = 0 -- A multiplier between 0 to 1.

-- -- Target-related
local fountains = {
workspace.RingBTMCenter.Fountain1.cannon.core.fountain,
workspace.RingBTMCenter.Fountain2.cannon.core.fountain,
workspace.RingBTMCenter.Fountain3.cannon.core.fountain,
workspace.RingBTMCenter.Fountain4.cannon.core.fountain,
workspace.RingBTMCenter.Fountain5.cannon.core.fountain,
workspace.RingBTMCenter.Fountain6.cannon.core.fountain,
workspace.RingBTMCenter.Fountain7.cannon.core.fountain,
workspace.RingBTMCenter.Fountain8.cannon.core.fountain
}
local speedRange = Vector2.new(0, 90) -- Set the minimum and maximum speed here. (MinimumValue, MaximumValue)

-- -- Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

-- -- Dynamic variables
local mousePositionOnClick = Vector2.zero -- Starting from the point where the mouse clicked.
local mousePositionOnMove = Vector2.zero -- Updates every mouse move.

local trackingConnection : RBXScriptConnection
local isTrackingMouse = false
local isMouseOverKnob = false

-- Functions

-- -- A linear interpolation (Lerp) function for speed.
local function GetNewSpeed(Value : number) : number
	return speedRange.X + (speedRange.Y - speedRange.X) * math.clamp(Value, 0, 1)
end

-- -- Slides with the mouse.
local function UpdateSlider(Value : number)
	knob.Position = UDim2.new( -- Retain most of its position minus X.Scale.
		UDim.new(Value, knob.Position.X.Offset),
		knob.Position.Y
	)
end

-- -- Get the "delta" between the initial position of click to the current mouse position.
local function GetDelta()
	return mousePositionOnMove - mousePositionOnClick
end

-- -- Start tracking the mouse upon pressing.
local function StartTrackingMouse()
	if isTrackingMouse then
		return
	end

	mousePositionOnClick = UserInputService:GetMouseLocation() -- Set initial mouse position.

	trackingConnection = UserInputService.InputChanged:Connect(function(Input)
		if Input.UserInputType == Enum.UserInputType.MouseMovement then
			local barCurrentSize = slider.AbsoluteSize.X
			mousePositionOnMove = UserInputService:GetMouseLocation()

			local delta = GetDelta()
			local scaleOffset = delta.X / barCurrentSize
			local newPosition = math.clamp(previousSliderValue + scaleOffset, 0, 1)

			sliderValue = newPosition
			
			for i, fountains in pairs(fountains) do
				fountains.Speed = NumberRange.new(GetNewSpeed(newPosition))
			end

			UpdateSlider(newPosition)

			-- This just updates the textbutton's text. You can remove this safely if you don't use a textbutton, or you just don't want text.
			knob.Text = tostring(math.floor((newPosition * 100)) / 100)
		end
	end)

	previousSliderValue = sliderValue

	isTrackingMouse = true
end

-- Stop tracking the mouse upon user releasing it.
local function StopTrackingMouse()
	if not isTrackingMouse then
		return
	end

	trackingConnection:Disconnect()

	isTrackingMouse = false
end

knob.MouseButton1Down:Connect(StartTrackingMouse)
UserInputService.InputEnded:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		StopTrackingMouse()
	end
end)

If it is client-sided, how can it become server-sided
(I assume with remote events or other methods)

Client sided, it changes UI so put it as a local script.

It is a LocalScript because it uses UserInputService. You can use RemoteEvents for client-server-client communication.

I’ll attempt to work on that.

What about only keeping the slider (gui) on my screen only?
To prevent others from messing with it.

What do you mean? Is this slider only available to you?

It should be.
It is meant to control the speed of certain particles, in a specific manner. I intend it to only be controlled by me (in the game).

Screen Shot 2023-01-09 at 10.01.43 AM
This is the slider in question,

Screen Shot 2023-01-09 at 10.02.24 AM
This is the location.

After the player stops moving the slider send a RemoteEvent, after which you set the Particles based on that.

Place this UI in ServerStorage, and then you can have a script manually assign it’s parent to your playergui. You should put the RemoteEvent in ReplicatedStorage so all players can connect to it.

1 Like

Not sure if this is correct.

-- -- Services & Events
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ValueChanged = ReplicatedStorage:WaitForChild("ValueChanged")

I added replicated storage and the event I want to use.

for i, fountains in pairs(fountains) do
				ValueChanged:FireServer()
			end

Then implemented it into this part of the script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ValueChanged = ReplicatedStorage:WaitForChild("ValueChanged")
local fountains = {
	workspace.RingBTMCenter.Fountain1.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain2.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain3.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain4.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain5.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain6.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain7.cannon.core.fountain,
	workspace.RingBTMCenter.Fountain8.cannon.core.fountain
}

ValueChanged.OnServerEvent:Connect(function()
	fountains.Speed = NumberRange.new(GetNewSpeed(newPosition))
end)

Then added a script in ServerScriptService to make it connect.
(It mentions “GetNewSpeed” and “newPosition” are unknown (orange underline))