I want to make it so when you press d and hold it it keeps on adding 15 and moving 15 up Idk how to do it, any help?
Mouse.KeyDown:connect(function(key) key = key:lower() if key == d' then Heart.Position = Heart.Position + UDim2.new(0.0, 15, 0.0, 0) end end)
Do the following:
local down = false -- variable used to see if the key is down Mouse.KeyDown:connect(function(key) key = key:lower() if key == 'd' then down = true -- starts moving end end) Mouse.KeyUp:connect(function(key) key = key:lower() if key == 'd' then down = false -- stops moving end end) while wait(0.1) do -- how long it waits in between movements if down == true then Heart.Position = Heart.Position + UDim2.new(0.0, 15, 0.0, 0) -- moves it end end
Please note that KeyDown/Up are deprecated, and can be removed at any time, so you should consider using UserInputService instead.
Hope I helped :)
~TDP
It would probably be something like this:
local dDown = true --Define Variable Mouse.KeyDown:connect(function(key) --KeyDown Function key = key:lower() if key == "d" then dDown = false end end) Mouse.KeyUp:connect(function(key) --KeyUp Function key = key:lower() if key == "d" then dDown = false end end) while wait() do if dDown == true then --Declare If Statement Heart.Position = Heart.Position + UDim2.new(0.0, 15, 0.0, 0) end end