Can you try printing what Player
is so you can see if it is in fact grabbing the player and it isn’t nil?
It’s print
the same thing like i print
Hit.Parent
Player:IsInGroup()
doesn’t exist, instead, I suggest doing
game.Workspace.GroupChest.TriggerPart.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player:GetRankInGroup(7104281) > 0 then
--[[
Script Here
]]--
end
end)
The key change here being if PlayerGetRankInGroup(7104281) then
You can get more info about it here: Player | Documentation - Roblox Creator Hub
cough cough
It does exist.
The problem, reading the error message, says “attempt to index NIL with ‘IsInGroup’”
This error message means the thing he’s calling :IsInGroup() on, is nil. But it isn’t nil as the print shows.
I always recommend using
hit:FindFirstAncestorWhichIsA(“Model”)
for getting the player’s character from the touching part, as it might be a tool that is touching or something else
game.Workspace.GroupChest.TriggerPart.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Player:IsA("Player") and Player:IsInGroup(7104281) then
--> script here
end
end)
I forget this is a function sometimes.
I see, I must’ve missed it in my first glance at the functions list. Anyways, wrapping the whole part the checks if the player’s in the group with if Player then
might fix the issue. I always do this myself to avoid this sort of issue and it hasn’t failed me to this day.
if Player then
Is always a good line to have, I use it too.
But @Nogalo’s solution should do the trick and if it doesn’t. I don’t know what’s wrong because they’re both printing out the player’s name…
Yeah me too, i am so confused where the problem is
I don’t think @Nogalo’s solution fixes anything more than what we’ve gotten to, because the output doesn’t say it didn’t find anything with the player’s name. Speaking of the output, @JavaKingz would you mind doing print(Player.ClassName)
to make sure we’re dealing with the player and not the character?
I Tried it,but output kept sending me error
you should try moving the script to serverscriptservice or workspace, and not put it in PlayerStarterScripts
You should try to do print(Player.ClassName)
and tell us the results.
The problem is that the part is touching other parts when the game starts, so you need to check if the part is a descendant of a player’s character and get the player by doing local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
To make sure that the variable Player
is equal to something we do if Player then
, now that we know the variable Player
is equal to something, we check if it is a ‘Player’ by doing Player:IsA("Player")
, after we did that, we need to check if the Player is in the group and to do that we do Player:IsInGroup(7104281)
(hoped that help you understand it better)
good point, the part might be touching baseplate the whole time thus firing the error all the time
I disagree with the need to check the class because :GetPlayerFromCharacter()
will always return an instance of the class Player
if it’s not nil, hence rendering that bit useless.
Btw guys,Does the problem just because i using localscript?
I don’t think this is where the problem is emerging from, but I definitely suggest moving this to a server script, because it’ll be checking for every player not just one. There is a possibility that this is the root of the problem though.
Try just adding that
if Player then
--in group stuff and rest of code
end
That will fix it.