01 | local Main = script.Parent |
02 | local Players = game:GetService( "Players" ) |
03 | local oGUI = script:FindFirstChild( 'ScreenGui' ) |
04 |
05 | Main.Touched:Connect( function (Hit) |
06 | local Player = Players:GetPlayerFromCharacter(Hit.Parent) |
07 | local PlayerGui = Player.PlayerGui |
08 |
09 | if oGUI and Player then |
10 | Main.Sound:Play() |
11 | for n = 0 , 2 , 0.2 do |
12 | Main.Sound.Volume = n |
13 | print ( 'Hi!' ) |
14 | local GUI = oGUI:Clone() |
15 | GUI.Parent = PlayerGui |
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.
01 | local Main = script.Parent |
02 | local Players = game:GetService( "Players" ) |
03 | local oGUI = script:FindFirstChild( 'ScreenGui' ) |
04 |
05 | Main.Touched:Connect( function (Hit) |
06 | local Player = Players:GetPlayerFromCharacter(Hit.Parent) |
07 |
08 | if oGUI and Player then |
09 | local PlayerGui = Player.PlayerGui |
10 | Main.Sound:Play() |
11 | for n = 0 , 2 , 0.2 do |
12 | Main.Sound.Volume = n |
13 | print ( 'Hi!' ) |
14 | local GUI = oGUI:Clone() |
15 | GUI.Parent = PlayerGui |