Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the GUI and Sound keep on going in this server script ?

Asked by 4 years ago

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

0
Can you tell us what is going wrong? What is happening that you don't want? And do you get any errors? Spjureeedd 385 — 4y
0
Testing it again there was an error , 10:59:53.284 - Workspace.Part.Script:8: attempt to index local 'Player' (a nil value) Redyblazeyy 31 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
Ad

Answer this question