Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with this mouse hold script?

Asked by
Mystdar 352 Moderation Voter
9 years ago

This is a **local script **in a tool, it is only supposed to run while the tool is equipped and is meant to play an animation when the mouse is held for 4 (or more) seconds.

Absolutely nothing happens, no printing colour changing or animation playing, no output help either.

while script.Parent.Equiped.Value == true do -- There is a BoolValue called Equipped that
                                        -- Becomes true when the tool is equiped
        mouse = game.Players.LocalPlayer:GetMouse()

        mouseDown = false

        startedDown = 0

        -- `mouse` a Mouse object from, e.g., theLocalPlayer:GetMouse()

        mouse.Button1Down:connect( function()
            mouseDown = true
            -- From now on, held
            startedDown = tick() -- Current time, in seconds
        end)

        mouse.Button1Up:connect( function()
            mouseDown = false
            if tick() - startedDown>4 then
                script.Parent.Blade.BrickColor = BrickColor.new("Pastel Blue")
                script.Parent.Attack:Play()
                script.Parent.Blade.BrickColor = BrickColor.new("Medium stone grey")
            end
        end)

        while wait() do
            if mouseDown then
                print(
                    "Has been held for ",
                    tick() - startedDown,
                    -- Time between now and when `startedDown` was set
                    "seconds"
                )
            else
                print("Not held.")
            end
        end
    end
0
You spelled Equipped wrong on line 1. Discern 1007 — 9y
0
The value is called Equiped, so it is not a problem, I realized that and have changed it, in game. Mystdar 352 — 9y

Answer this question