How should I get a boolvalue located in a players' PlayerGui to change on touch of a part?

Have tried a bit but I unfortunately really can’t write a script for this myself.

You can get the part parameter that is being referenced in the Touched event when fires, and then continue to check if you can get the player from that parent of the part using GetPlayerFromCharacter, then get the PlayerGui from the previous player and you would find your boolvalue inside the player Gui, and change it.

part.Touched:Connect(function(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local playerGui = player:FindFirstChild("PlayerGui")
        if playerGui then
            local boolValue = playerGui:FindFirstChild("BoolValue")
            if boolValue and boolValue:IsA("BoolValue") then
                boolValue.Value = true -- or false idk
            end
        end
    end
end)

Thank you so much! This worked, will help with a few systems I’m working on for my game

1 Like