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

I need this ImageButton to go back to its place once I let go?

Asked by 5 years ago
Edited 5 years ago

I have a script that when you HOLD the rock image it moves to your mouse but when I let go it doesn't go back to its spot?

If you are wondering why I have "-660, -650" its to make the image be on my mouse and not somewhere else

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()

script.Parent.MouseButton1Down:Connect(function()
    repeat
        wait()
        local val = script.Parent.CanMove.Value
        wait(0.01)
        script.Parent.Durability.Visible = false
        script.Parent.Position = UDim2.new(0, mouse.X -660, 0, mouse.Y -650)
    until val == 1
end)

script.Parent.MouseButton1Up:Connect(function()
    local val = script.Parent.CanMove.Value
    val = 1
    script.Parent.Durability.Visible = true
    script.Parent.Position = UDim2.new(0,0,0,0)
end)
0
val only exists in the function on line 15. Vove the variable to the top of your code so both functions have access to it. You also need to reset the value when you press the mouse button down. User#5423 17 — 5y

Answer this question