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

OnTouch script isn't working?

Asked by 7 years ago
Edited 7 years ago
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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

Ad
Log in to vote
0
Answered by 7 years ago

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.

Answer this question