Alright. It's a fine piece of code you have right there, but unfortenately we have to make it way more complicated.
I hereby introduce to you: RemoteEvents!
Wiki page: https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
Basically, when you are playing roblox, you are a client playing on a server. The client is your computer, and the server is something roblox is running on their own.
There are two types of scripts that you have to know about when trying to communicate with the server.
Serverscripts and Localscripts.
Serverscripts are named "Script" in roblox studio
The code you wrote was written in a localscript. Localscripts only change information on the client, in other words, on your computer (Locally. it is in it's name). It does not replicate over to the server.
That means only you can see what changes the localscript does.
We need the client to communicate with the server so the server can make the change, which will give everyone the ability to see what is happening! We will use RemoteEvents for this.
Step 1:
You have to put a RemoteEvent in "ReplicatedStorage". This is a "Vault" that both the client and the server can see. This is our way of communicating with the server. I will name it "enableParticles"
http://gyazo.com/be72eb22d9281c0c8cc47c3b86500cfe
Step 2:
Then we get to the part of setting up a localscript:
First I will listen to the MouseButton1Click event to detect whenever the player clicks the button. Then we have to locate the "enableParticles" event and define it with a variable.
NOTE: I do not change the particles state on the client. I will do that in a serverscript later.
It is important that you keep your scripts organized with variables. And please do use game:GetService() for services that you need.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local particleEvent = ReplicatedStorage:WaitForChild("enableParticles")
script.Parent.MouseButton1Click:Connect(function()
particleEvent:FireServer()
end)
That's the localscript. Now that we have the "Button" that the client can press, we have to make a script that fires every time that "button" is pressed.
I placed a ServerScript inside "ServerScriptService". This is a good location for you to store serverscripts.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local particleEvent = ReplicatedStorage:WaitForChild("enableParticles")
particleEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local particle = character.Chest.Liquid.Particles
particle.Enabled = not particle.Enabled
end)
I hope you understood something of the cluster I just launched at you
If you got questions, please contact me at my discord: Sethex#6760
Good luck with your scripting!
~Sethex