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

OnTouch script isn't working?

function onTouch(player)
	local group = 2551575
	local rank = 239
	if player:GetRankInGroup(group) >= rank then
		player.CurrentCamera.Part.CanCollide = false
	end
end
script.Parent.Touched:connect(onTouch)

11:34:31.658 - GetRankInGroup is not a valid member of Part 11:34:31.658 - Stack Begin 11:34:31.658 - Script 'Workspace.Camera.Part.Script', Line 4 11:34:31.659 - Stack End Output ^

2 answers

✓ Accepted answer

The Touched event passes the base part that touched the base part that has the event connected so 'player' will be the base parts and it does not have the function GetRankInGroup.

We can still get the player using the function GetPlayerFromCharacter.

Example:-

local group = 2551575
local rank = 239
local plrServ = game:GetService('Players')

local function onTouch(hit)
	local plr = plrServ:GetPlayerFromCharacter(hit.Parent)

	if plr and plr:GetRankInGroup(group) >= rank then
		-- other code here
		print('code ran')
	end
end
script.Parent.Touched:connect(onTouch)

I hope this helps, please comment if you do not understand how / why this code works.

The touched event returns a hit, which can be anything. E.g Part. But in this case it will return a Body Part.

Therefore, since the body part is under the character you can use hit.Parent.

We are still not done there... this returns only the character on the player. To find the player use GetPlayerFromCharacter. Then finally you have the player and call GetRankInGroup() on it.

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