2023-04-28

Tag a player who touches script.Parent

So I want this to tag a player tho it just does nothing!

local playersTouching = {}

local function onPartTouched(part, player)
    if part == script.Parent and player and player:IsA("Player") then
        player:SetAttribute("Hiding", true)
        playersTouching[player] = true
    end
end

local function onPartTouchEnded(part, player)
    if part == script.Parent and player and player:IsA("Player") then
        player:SetAttribute("Hiding", nil)
        playersTouching[player] = nil
    end
end

script.Parent.Touched:Connect(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
    if humanoid then
        onPartTouched(script.Parent, humanoid.Parent)
    end
end)

script.Parent.TouchEnded:Connect(function(otherPart)
    local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
    if humanoid then
        onPartTouchEnded(script.Parent, humanoid.Parent)
    end
end)

So I executed it on Roblox and the Player touches the script.Parent and doesnt get tagged. Also goal of this is to detect when player is touching certain part when another part with a script touches them. If my method doesnt work please give me another method. Thx!

AMMEDNMENT: Now my detecing script aint working lol so is it the same issue where I am getting char instead of player:

script.Parent.Touched:Connect(function(player)
    print("TOUCHED")
    if player:GetAttribute("Hiding") then
        print("tag player touch????")
    else
        print("HMM")

    end
end)


No comments:

Post a Comment