I have no idea what i am doing with this script, tested it, got nowhere

sorry if im not technical enough to explain this hot garbage I did but its really the best I can do so far, but to the point:

Im kinda having an issue with this script for a double knobed sink I built for this hangout place im curently making changes on, can anyone help me with this? I know it looks like garbage, but to be honest I know nothing about coding or scripting. this is my first basic script I kinda want to learn.

for even more refined information I basicly made a model of the sink set model, and a small water stream as a part.
both of the knobs have Click Detectors and whenever one is clicked it should turn water slightly visable for 10 seconds
both knobs and the water stream are part of the script including the click detectors.
I don’t even know what I am doing wrong, apart from being a blockhead of a scripter XD

3 Likes

I can hardly see anything on the screenshot, can you please copy and paste the code on this topic?

(Please make sure to use ``` when displaying code here!)

For self-debugging, try to place some print() functions around the code, and see which part of the code prints while which doesn’t.

3 Likes

understood let me grab it real quick

1 Like

–defined objects

local hot = script.Parent.Knob.Hot
local clickdetectorhot = hot.ClickDetector
local cold = script.Parent.Knob2.Cold
local clickdetectorcold = cold.ClickDetector2
local water = script.Parent.Water

–hot function?

local function Clicked()
while true do
water.Transparency = 0.5
wait(10)
then water.Transparency = 1

end
end

clickdetectorhot.MouseClick:Connect(Clicked)

–cold function?

local function Clicked2()
while true do
water.Transparency = 0.5
wait(10)
then water.Transparency = 1

end
end

clickdetectorcold.MouseClick:Connect(Clicked2)

Blockquote

1 Like

Don’t think you’re supposed to place “then” when setting the water’s Transparency. That’s only used for if or if/else statements.

Going away for a few hours, sorry.

1 Like

thank you this would prob help, also i got to go and do things aswell, i might come back to see more feedback to refine this code i made

1 Like

I don’t mean to be rude but… yeah this is absolutely horrendous.

First off, then is used only in if statements. It cannot be used in the sense of doing something after something has happened. Also, why are you using two while true do loops? They’re for doing something while a value is true, not for normal things.

Also, since there is no value for if it is enabled or not, it can be spammed, thus breaking it entirely and having it be completely unreliable.

Here’s what you should do:

  • Remove the while true do loops, they’re HORRIBLE
  • Don’t use “then” outside of “if” functions
  • Create a value for if it’s enabled or not. You can do this by creating a variable like this:
local Enabled = false
hot.MouseClick:Connect(function()
if enabled then
    hotparticles.Enabled = false
    Enabled = false
end
if not enabled then
Enabled = true
hotparticles.Enabled = true
task.wait(10)
Enabled = false
hotparticles.Enabled = false
    end
end)
3 Likes

yeah i thought the same thing when i saw my code for the first time, but its not bad for a start right?

1 Like

the reason i did 2 “while true do” loops is cuase i asumed it would be becuase i have two knob functions but i digress your methods would prob help me anyways cuase it might not function to begin with

1 Like

so im asuming i remove all the code i did originaly, and i edit what you gave me to what i have in my locals this will function correct?

2 Likes

sorry im kinda slowly trying to understand whats happing here but ill figure it out eventualy

1 Like

i think your giving me a script for water particals, im using a part XD sorry about that

1 Like

Your variables need to have different names, and use ClickDetectorHot and ClickDetectorCold, not the parts themselves.

3 Likes

Maybe create a transparent part around both knobs and drop a ClickDetector in that.

local water = script.Parent.Parent.Water -- wherever it is
local click = script.Parent -- ClickDetector
local db = true

function Water()
	if db then db = false
		water.Transparency = 0.5 task.wait(10)
		water.Transparency = 1
		db = true
	end
end

click.MouseClick:Connect(Water)```
1 Like

yeah i already kinda found a way of making the sink work. but thanks for the information tho.

im also going to try to see if this works

yeah this set of code actually works!

all i had to do with this script was put 2 scripts inside the hot and cold knobs, and leave the water as part of the main model, and it surprisingly functioned like it was supposed to!

Great! I put that in one script and part, due to the fact both your knobs were doing the same thing.
(little fade in and out add)

local rs=game:GetService("RunService")

for trans = 1, 0, -0.01 do
	water.Transparency = trans rs.Stepped:Wait()
end water.Transparency = 0.5

task.wait(7.5)
for trans = 0.5, 1, 0.01 do
	water.Transparency = trans rs.Stepped:Wait()
end water.Transparency = 1

This is good but it could be much easier to manage in just one script.
@Iced_ElEctriced This lowers script lag, so try this too:

local water = script.Parent.Parent.Water -- Water
local WaterActive = false

for _, detectors in pairs(script.Parent.Parent:GetDescendents()) do
if detectors:IsA("ClickDetector") then
detectors.MouseClick:Connect(function()
if WaterActive then
water.Transparency = 1
WaterActive = false
else
		water.Transparency = 0.5
		WaterActive = true
task.wait(10)
WaterActive = false
water.Transparency = 1
end
end)
end