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

I'm trying to make a IsInGroup script for practice. Any ideas as to why it wont or any solutions?

So, I'm trying to experiment with IsInGroup, GetRankInGroup, and GetRoleInGroup. But for some reason I can't seem to get any of them to work. I looked at tutorials and tried doing it myself, but still nothing. As shown below on line 4, the IsInGroup shows when a colon is added. So any explanation as to why this won't work?

local Player = game.Players.LocalPlayer

function Touched(plr)
	if Player:IsInGroup(3713839) then
		print("Works!")
	end
end

script.Parent.Touched:Connect(Touched)

7 comments

0

need: error message. i see your problem but you tell us too

0

23:11:06.118 - Workspace.Part.Script:4: attempt to index upvalue 'Player' (a nil value)

0

You're using the Touched event wrong. Look at what the parameter is on the wiki. Also, Player is nil because you can't reference a local player in a server-script. Local player only exist locally.

0

The touched event, I've used before and it worked. I put the code in the server script in a local script, but nothing,

1

Oof nevermind, the touched event doesn't work.

0

I would like to recommend you use game:GetService("Players") instead of game.Player.LocalPlayer. I can't remember of they're different things.

0

How would I make the function work? Even when I change the function to script.Parent.Touched:Connect(function(), it doesn't work.

1 answer

✓ Accepted answer

The issue with your script is that you cannot get the player using game.Players.LocalPlayer in a ServerScript and you cannot use the Touched Function in a local script. ROBLOX came up with a solution how you can get the player on a touched event using GetPlayerFromCharacter:

https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter

It essentially returns the player from the character.

You can put the ServerScript in a part.

-- function that runs when the part is touched.
script.Parent.Touched:Connect(function(hit)
-- variable to get the player from hit.Parent.
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
--Checks if the player is in group and prints work.
if player:IsInGroup(3713839) then
	print("Works!")
end

end)

4 comments

0

Thank you for your answer. It works. All I got to do now is add in some debounce.

0

So now how would I put this so if you click a TextButton?

0

Nevermind.

0

Nevermind, I still need help with my second question,

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