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

When Players touch the part, And if they are in Group, They should teleport?

However, when I touch the part, it's not teleporting the player IsInGroup is not a valid member of Part

script.Parent.Touched:Connect(function(hit)
    if hit.Parent ~= nil then
        if hit:IsInGroup(6138889) then
            if hit.Parent:FindFirstChild("Humanoid") then
                print("You are in team")
		hit.Parent.Character.Humanoid.CFrame = CFrame.new(1279.251, 238.51, -448.12)	
            end
        else
            print("You're not in the team")
        end
    end
end)

2 comments

0

what is the output error?

0

IsInGroup is not a valid member of Part

1 answer

Hello. The problem is that you did not check if the part hit was a player before you called the :IsInGroup() function. Try this:

script.Parent.Touched:Connect(function(hit)
   local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

    if player then
        if player:IsInGroup(6138889) then
            if hit.Parent:FindFirstChild("Humanoid") then
                print("You are in team")
        hit.Parent.Character:SetPrimaryPartCFrame(CFrame.new(1279.251, 238.51, -448.12))
            end
        else
            print("You're not in the team")
        end
    end
end)

The player variable will get the player from its character which is hit.Parent. Then there's an if statement checking if the player is existent. Please accept this answer and upvote it if it helped.

4 comments

0

Character is not a valid member of Model, Now it's the error >.<

0

hit.Parent.Humanoid.CFrame*

0

CFrame is not a valid member of Humanoid

0

i fixed it

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