I cant figure out how do i make this script on a textbutton

So, i have this script that i made and i want it to be able to run on a textbutton. But, I just cant figure out how do i make it work? I made it so that when u hold it, it executes

So please help, thanks.

Here is the code:

You probably want to mark the solution as yourself btw

(To write formatted code on the forum, theres a button “</>” either in the settings or on the toolbar for you to paste code in)
You’ve gotta be more specific about what you want to achieve. But these are the errors I deduce from inference:
For button.Parent to be a valid 3D object to raycast from, it’s in the workspace. If the button is in workspace, the local script under it won’t work since local scripts don’t work in the workspace. If otherwise you can see the button then its in a frame or screen gui which are not valid 3D objects to raycast from.
Here’s how I would rewrite your script (make sure the button has a local script and is in a screen gui or in a frame under a screen gui in starter gui)

     
local button = script.Parent
local char = game.Players.LocalPlayer.Character
local holdingKey = false
 
local uis = game:GetService("UserInputService")
 
local leftAnim = button.Parent.Humanoid:LoadAnimation(script:WaitForChild("WallrunLeft"))
local rightAnim = button.Parent.Humanoid:LoadAnimation(script:WaitForChild("WallrunRight"))
 
button.MouseButton1Down:Connect(function()
    holdingKey = true
end)
 
button.MouseButton1Up:Connect(function()
    holdingKey = false
end)
 
game:GetService("RunService").Heartbeat:Connect(function()
    local raycastParams = RaycastParams.new()
    raycastParams.FilterType = Enum.RaycastFilterType.Exclude
    raycastParams.FilterDescendantsInstances = {char}
    raycastParams.IgnoreWater = true
 
    local rayL = workspace:Raycast(char.HumanoidRootPart.CFrame.Position, -char.HumanoidRootPart.CFrame.RightVector * 3, raycastParams)
    local rayR = workspace:Raycast(char.HumanoidRootPart.CFrame.Position, char.HumanoidRootPart.CFrame.RightVector * 3, raycastParams)
 
    local ray = rayL or rayR
 
    if ray and holdingKey then
        if ray == rayL then
            if not leftAnim.IsPlaying then leftAnim:Play() end
            rightAnim:Stop()
        else
            if not rightAnim.IsPlaying then rightAnim:Play() end
            leftAnim:Stop()
        end
 
        local part = ray.Instance
 
        local weld = button.Parent.HumanoidRootPart:FindFirstChild("WallrunWeld") or Instance.new("WeldConstraint")
        weld.Name = "WallrunWeld"
 
        weld.Part0 = button.Parent.HumanoidRootPart
        weld.Part1 = part
 
        local bp = button.Parent.HumanoidRootPart:FindFirstChild("WallrunBodyPosition") or Instance.new("BodyPosition", button.Parent.HumanoidRootPart)
        bp.Name = "WallrunBodyPosition"
        bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bp.Position = button.Parent.HumanoidRootPart.Position + button.Parent.HumanoidRootPart.CFrame.LookVector * 10
    else
        for _, child in button.Parent.HumanoidRootPart:GetChildren() do
            if child.Name == "WallrunWeld" or child.Name == "WallrunBodyPosition" then
                child:Destroy()
            end
        end
 
        leftAnim:Stop()
        rightAnim:Stop()
    end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.