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)
There is an error : 12:12:01.818 - Workspace.Part.Script:8: attempt to index local 'Player' (a nil value) This is a server script BTW
Touched events don't always fire on player characters. Make sure it's a character, then get the gui.
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) if oGUI and Player then local PlayerGui = Player.PlayerGui 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)