local Main = script.Parent local Players = game:GetService("Players") local oGUI = script:FindFirstChild('ScreenGui') Main.Touched:Connect(function(Hit) local Player = Players:GetPlayerFromCharacter(Hit.Parent) local PlayerGui = Player.PlayerGui if oGUI and Player then Main.Sound:Play() for n = 0 , 2 , 0.2 do Main.Sound.Volume = n print('Hi!') local GUI = oGUI:Clone() GUI.Parent = PlayerGui wait(3) GUI:Destroy() for y = 2 , 0 , 0.2 do Main.Sound.Volume = y wait(0) Main.Sound.Volume:Stop() end end end end)
I'm trying to make a thing where if you touch it a GUI pops up and it plays a song PS : script is a server script
Line 18 is incorrect:
for y = 2, 0, 0.2 do
Now for the fun part: explaining what you did wrong.
Think of the parameters of a numeric for loop this way:
for var = x, y, z do
There are certain conditions that require z
to be a specific number:
If x < y
, z
must be positive.
If x > y
, z
must be negative so that the loop counts down instead of up.
Because x > y
is true for your parameters, your parameter z
must receive a negative number as an argument. Because z
is positive, the loop does not run because it cannot count up to 0 from 2. Basic logic.
To fix the issue, simply make z
negative:
for y = 2, 0, -0.2 do