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

How to unanchor a player after player clicks text button?

I don't know how to unanchor a player when they have clicked a text button.

function onClicked(click)
	local player = click.Parent.HumanoidRootPart
	if player then
		wait(17.1)
		player.Anchored = false
	end
end

script.Parent.Touched:Connect(onClicked)

1 answer

✓ Accepted answer

The .Touched signal is fires upon physical contact between two Instances, it does not represent interface-interaction. The event you're looking for is .MouseButton1Click; a signal inherited from the GuiButton base-class.

script.Parent.MouseButton1Click:Connect()

This doesn't resolve the issue at hand though, as there is no parameter that contains a Player Object given by this signal. Also, it's best to use proper naming conventions when declaring variables as to avoid confusion throught your Script:

local Player = game:GetService("Players").LocalPlayer

local Button = script.Parent

local function UnanchorCharacter()
    local Character = Player.Character or Player.CharacterAdded:Wait()
    local Humanoid = Character:FindFirstChildOfClass("Humanoid")
    if (Humanoid and Humanoid.Health > 0) then
        Humanoid.RootPart.Anchored = false
    end
end

Button.MouseButton1Click:Connect(UnanchorCharacter)

If this helped, don't forget to accept this answer!

1 comment

0

Your code works, but the player isn't able to jump. Whenever they do, the player just stops for a brief moment and walk again.

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