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
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
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)
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
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)```
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