Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"PlayerGui is Not A Valid Member of Player"?

Im Trying to make a "Rage"GUI, That when press E, or Clicking on it, affects players from a distance, blinding them, and teleports the player who is clicking, to a random player... But im having this error with the PlayerGui, when it tries to blind the Victim...

"PlayerGui is Not A Valid Member of Player"

I Alredy changed it to :WaitForChild, but the message changes, saying:

"Infinite Yield Possible on players[i]:WaitForChild("PlayerGui")

The Error is on Line 063 Sorry if I'm not explaining it right, Here's The Script:

LocalPLR = game.Players.LocalPlayer
Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
PTorso = game.Players.LocalPlayer.Character:WaitForChild("Torso")


local RSound = game.Workspace.RageSounds.FreddyKrueger
local Plrs = game.Teams.Survivor:GetPlayers()

Rage = 0
RageIsReady = false
GetRage = 100
Distance = 50
TPDistance = 300


function getrage()
Rage = Rage + GetRage
wait(0.01)
script.Parent.Text = "RAGE: "..Rage.." %"
if Rage >= 100 then
script.Parent.Text = "RAGE: Ready! Click to Use It!"
RageIsReady = true
end
end

function GetNearPly()
	
local Plrs = game.Players:GetPlayers()
local results = {}

for i=#Plrs,#Plrs do
 if (Plrs[i].Character ~= nil) then
  local t = Plrs[i].Character:FindFirstChild("Torso")
   if (t ~= nil) then
   if ((t.Position - PTorso.Position).magnitude <= Distance) and Plrs[i].Team ~= game.Teams.Freak then
   results[#results + 1] = Plrs[i]
end
end
end

return results

end

end

function Teleport()
local randplayer = Plrs[math.random(1, #Plrs)]	
print("Teleporting to: "..randplayer.Name.."")
LocalPLR.Character:MoveTo(randplayer.Character.Torso.Position)
end	



function TheRage()
Teleport()
RSound:Play()
wait(0.3)
local players = GetNearPly()

for i=1,#players do
local Blind = game.Lighting.RageGUI.FreddyK.Blind
Blind:Clone().Parent = players[i]:WaitForChild("PlayerGui")--- im having the error HERE
end

end


script.Parent.MouseButton1Click:connect(function()

if RageIsReady == true then
TheRage()
Rage = 0
RageIsReady = false	
script.Parent.Text = "RAGE: "..Rage.." %"

elseif RageIsReady == false then
print("Rage is Not Ready!")
end
end)

m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)

if key == "e" then
if RageIsReady == true then
TheRage()
Rage = 0
RageIsReady = false	
script.Parent.Text = "RAGE: "..Rage.." %"

elseif RageIsReady == false then
print("Rage is Not Ready!")
end
end
end)


Humanoid.HealthChanged:connect(getrage)

5 comments

0

KeyDown is deprecated, do not use it in new work.

0

The infinite yield isn't an issue. It just alerts you that it could possibly wait for longs periods of time if the child doesn't load, which it should.

0

ikr, but it seems to never load

0

You have LocalPlayer defined already, so why're you retyping it over and over? >.>

0

If your script is a server script(or normal script), then, you should change it to a LocalScript.

1 answer

✓ Accepted answer

I hope it works

LocalPLR = game.Players.LocalPlayer
Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
PTorso = game.Players.LocalPlayer.Character:WaitForChild("Torso")


local RSound = game.Workspace.RageSounds.FreddyKrueger
local Plrs = game.Teams.Survivor:GetPlayers()

Rage = 0
RageIsReady = false
GetRage = 100
Distance = 50
TPDistance = 300


function getrage()
Rage = Rage + GetRage
wait(0.01)
script.Parent.Text = "RAGE: "..Rage.." %"
if Rage >= 100 then
script.Parent.Text = "RAGE: Ready! Click to Use It!"
RageIsReady = true
end
end

function GetNearPly()

local Plrs = game.Players:GetPlayers()
local results = {}

for i=#Plrs,#Plrs do
 if (Plrs[i].Character ~= nil) then
  local t = Plrs[i].Character:FindFirstChild("Torso")
   if (t ~= nil) then
   if ((t.Position - PTorso.Position).magnitude <= Distance) and Plrs[i].Team ~= game.Teams.Freak then
   results[#results + 1] = Plrs[i]
end
end
end

return results

end

end

function Teleport()
local randplayer = Plrs[math.random(1, #Plrs)]  
print("Teleporting to: "..randplayer.Name.."")
LocalPLR.Character:MoveTo(randplayer.Character.Torso.Position)
end 



function TheRage()
Teleport()
RSound:Play()
wait(0.3)
local players = GetNearPly()

for i=1,#players do
local Blind = game.Lighting.RageGUI.FreddyK.Blind
Blind:Clone().Parent = game.Players.LocalPlayer.PlayerGui--- im having the error HERE
end

end


script.Parent.MouseButton1Click:connect(function()

if RageIsReady == true then
TheRage()
Rage = 0
RageIsReady = false 
script.Parent.Text = "RAGE: "..Rage.." %"

elseif RageIsReady == false then
print("Rage is Not Ready!")
end
end)

m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)

if key == "e" then
if RageIsReady == true then
TheRage()
Rage = 0
RageIsReady = false 
script.Parent.Text = "RAGE: "..Rage.." %"

elseif RageIsReady == false then
print("Rage is Not Ready!")
end
end
end)


Humanoid.HealthChanged:connect(getrage)

1 comment

0

xD i did such a small change and im not a professional scripter and i made it work xD np <3

This discussion is preserved as it was. New answers, comments, and votes are closed.