How to make a GUI that makes you anchor

This maybe dumb to ask but, how do i make a Gui Button that makes you anchor when you press it

It’s kinda easy tho, here’s my script.

local button = pathto.Button
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

button.MouseButton1Click:COnnect(function()
    local parts = character:GetChildren()
    for _, part in pairs(parts) do
        if part:IsA("Part") or part:IsA("BasePart") then
            part.Anchored = true
        end
    end
end)

u can just anchor the humanoidrootpart and it’s gonna freeze the whole character

omg i forgot, thank you. It really helps

small problems like you spelled Connect Wrong even capital words can sometimes cause an error also this is a better script:

local button = pathto.Button
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

button.MouseButton1Click:COnnect(function()
    local parts = character.HumanoidRootPart
            part.Anchored = not part.Anchored
end)

This script anchors then unanchors on demand

Sorry I just type fast, and I’m aware that Capital words can cause errors.

Yooooo, this off-topic, but LOL we both here

how is this off-topic?? i am just helping our fellow roblox user here and correcting some mistakes and improving his script

I know, but they won’t know what we mean when I say that

oh ok sorry lol (this message is to be ignore cuz of caps)

where do i put the script I’m confuse

Inside a Button, whether it’s TextButton or ImageButton.
It also must be a LocalScript.

ah okay thanks for letting me know

1 Like

so i kinda figure it out this is what i did

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local gui = player.PlayerGui[put the gui name here]
gui.MouseButton1Click:Connect(function()
	local part = character.HumanoidRootPart
	part.Anchored = not part.Anchored
end)

but thanks that you help, really appreciated

1 Like

Not sure why you referenced the player twice

but, just letting you know, this code only works if the button’s screengui has .ResetOnRespawn enabled, if you didn’t want that, this wouldn’t be the correct code, let me know if you didn’t want that

oops i forgot but i fix it already

1 Like

i made alot of edit of this lol

1 Like