✓ 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
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.