Touched Group Isn't Working

I want to make a gui enable when a player touches a part and is inside the group and has a rank higher than 15

It’s not printing out any errors.

I have tried changing the way i get the player and it still isn’t working. No errors either

local billboardgui = script.Parent.BillboardGui
local gui = game:GetService("StarterGui"):WaitForChild("Stage")
local MP = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local GP = 5470285


script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
			local plar = players:FindFirstChild(hit.Parent.Name)
	if plar:IsInGroup(GP)then
	 if plar:GetRoleInGroup(GP) > 15 then
			gui.Enabled = true
			end
		end
	end
	end)

I think the issue is you are enabling the gui which is in StarterGui and not in the players PlayerGui, try doing plar.PlayerGui.Stage.Enabled = true instead of gui.Enabled = true.

1 Like

One thing is, you should define plar as local plar = players:GetPlayerFromCharacter(hit.Parent) and the other thing is, you are trying to modify screen gui stored in starter gui. Changes applied to starter gui won’t be visible in player’s player gui until you reset, because the entire starter gui gets cloned in there. So what you have to do is:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plar = players:GetPlayerFromCharacter(hit.Parent)
		if plar:IsInGroup(GP)then
			if plar:GetRankInGroup(GP) > 15 then
				local plrGui = plar:WaitForChild("PlayerGui")
				local gui = plrGui:FindFirstChild("Stage")
				if gui then gui.Enabled = true end
			end
		end
	end
end)
2 Likes

This is the error i am getting - Workspace.Part.Script:12: attempt to compare number with string

Line 12 is if plar:GetRoleInGroup(GP) > 15 then

Ohh yeah I see, GetRoleInGroup returns a role name, use GetRankInGroup instead. (I modified the script above)

2 Likes

Use >= instead of >, Operators | Documentation - Roblox Creator Hub.

1 Like

Thanks, I can be an idiot at times, Trying use numbers with strings lmao

It’s alright, we all do mistakes :+1:

1 Like

Okay, So i am encountering the STRANGEST bug. So basically i’ve added a back button to make the gui.enabled = false and it works, however when i go on the button again it won’t reappear?

No errors at all and they both won’t but after i make it false it won’t reappear… very strange? Well tbh i’ve probs spelt something wrong. I’ve go through over it again and come back if i can’t fix it