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

(Player Name) is not a valid member of Players. Help anyone?

Asked by 4 years ago

Hi guys, this is my first ever question on here. So I'm trying to make a Camping-like game it is called Truth or Dare. All the other scripts work except for this one. The script is supposed to make a GUI pop up once a player touches a specific part. But when I touch the part, I look at the output and an error has popped up saying, "ally_playz336 is not a valid member of Players." So here is the script:

local GUI = script.Parent.ScreenGui -- You might want to change this to whatever your GUI is.
script.Parent.PlayerTouched:connect(function(hit)
    if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
        local plr = game.Players(hit.Parent.Name)
        if plr:FindFirstChild("PlayerGui") and not plr.PlayerGui:FindFirstChild(GUI.Name) then
            GUI.Clone().Parent = plr.PlayerGui
        end
    end
end)

I don't know if there is anything wrong with it, because it looks fine to me. The only problem is that it won't work. Help is greatly appreciated ????

2 answers

Log in to vote
0
Answered by 4 years ago

hit.Parent.Name is a part of hit.Parent. not a child (I think, correct me if im wrong), so an easier way to get the person touched would be to used GetPlayerFromCharacter.

Instead of using:

if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
        local plr = game.Players(hit.Parent.Name)

Try:

if hit.Parent  then
local plr = hit.Parent:GetPlayerFromCharacter

So the script would be:

local GUI = script.Parent.ScreenGui

script.Parent.PlayerTouched:connect(function(hit)
   if hit.Parent and game.Players:FindFirstChild(hit.Parent.Name) then
local plr = hit.Parent:GetPlayerFromCharacter
        if plr:FindFirstChild("PlayerGui") then
            GUI.Clone().Parent = plr.PlayerGui
        end
    end
end)

I hope that works!

Also I don't know why you need:

and not plr.PlayerGui:FindFirstChild(GUI.Name) then

But again, correct me if theres a reason. ;D

0
@fighterkirbyzx It still doesn't work. Another error has popped up in my output saying, "16:55:45.783 - Workspace.GUIGiver.Script:6: Expected '(', '{' or <string>, got 'if'" I don't think it works :( ally_playz336 -1 — 4y
0
what line was the error? manith513 121 — 4y
0
@manith513 The error had a 6 in it, so I think it may be on line 6. ally_playz336 -1 — 4y
0
wiat manith513 121 — 4y
View all comments (4 more)
0
what? :| ally_playz336 -1 — 4y
0
I know the issue manith513 121 — 4y
0
use game:GetService:("Players"):GetPlayerFromCharacter(hit.Parent) instead Fad99 286 — 4y
0
i forgot the () ;-; fighterkirbyzx 102 — 4y
Ad
Log in to vote
0
Answered by
manith513 121
4 years ago
Edited 4 years ago

NOW AFTER EDITS OFFICIALLY WORKING!

Sorry I glitched from my other comment can you tell me if this works I think you should try the script with this

local GUI = script.Parent.ScreenGui

script.Parent.Touched:Connect(function(hit)
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
            if plr:FindFirstChild("PlayerGui") then
                    GUI.Clone().Parent = plr.PlayerGui.ScreenGui
        end
        end

end)

always remember to add the next child screen gui after player gui btw

0
Sorry I forgot about the parenthesis try this now manith513 121 — 4y
1
GetPlayerFromCharacter is a method of game.Players. The line should read "local player = game.Players:GetPlayerFromCharacter(hit.Parent)". An then you'll need to check if player exists. See the bottom of this page https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter vector3_zero 1056 — 4y
0
^ Fad99 286 — 4y
0
@vector thanks I forgot about that manith513 121 — 4y
View all comments (10 more)
0
@manith I dont think this one works either. PlayerTouched is not a valid member of Part... :c ally_playz336 -1 — 4y
0
also why dont you use script.Parent.Touched:Connect? I've never even used PlayerTouched fighterkirbyzx 102 — 4y
0
@ally lemme edit the script real quick manith513 121 — 4y
0
@ally finished manith513 121 — 4y
0
@ally I just made some new edits that i tested and it should work it works on my behalf manith513 121 — 4y
0
@ally for some reason the ends are misplaced to move the end on line 8 under the if plr find first child state ment on the same line and move the end on line 9 to the if plr is a statement on the same line manith513 121 — 4y
0
Line 5 should read "if plr then". It will either exist or not. You just need to check if it exists, and if it does it can only be a player as we got it from GetPlayerFromCharacter, which returns a player or nil. vector3_zero 1056 — 4y
0
right thank you manith513 121 — 4y
0
vector3_zero do you mind looking at one of my posts about an arrow direction please? you look like a pretty good scripter do you mind helping me please? manith513 121 — 4y
0
vector3_zero wait is there a difference between hit.Parent:GetPlayerFromCharacter() and game.Players:GetPlayerFromCharacter(hit.Parent)? fighterkirbyzx 102 — 4y

Answer this question