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

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

Asked by 5 years ago
01local Main = script.Parent
02local Players = game:GetService("Players")
03local oGUI = script:FindFirstChild('ScreenGui')
04 
05Main.Touched:Connect(function(Hit)
06local Player = Players:GetPlayerFromCharacter(Hit.Parent)
07local PlayerGui = Player.PlayerGui
08 
09if 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
View all 25 lines...

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

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
5 years ago

Touched events don't always fire on player characters. Make sure it's a character, then get the gui.

01local Main = script.Parent
02local Players = game:GetService("Players")
03local oGUI = script:FindFirstChild('ScreenGui')
04 
05Main.Touched:Connect(function(Hit)
06local Player = Players:GetPlayerFromCharacter(Hit.Parent)
07 
08if 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
View all 25 lines...
0
Once you fix that, tell me if there are any other errors, and I'll edit my post to fix them. compUcomp 417 — 5y
0
Also, you can't access things inside of PlayerGui from a server script, you can put GUI into it, but you can't remove anything or see things in it MrLonely1221 701 — 5y
1
Not entirely correct ^. If the server either clones or creates a child and assigns its Parent to a player's PlayerGui, the server can access that child, but it still can't access anything else in the PlayerGui. DeceptiveCaster 3761 — 5y
Ad

Answer this question