Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can i make this constant?

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)

2 answers

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

1 comment

0

Since this is GUI code, it's better to use RenderStepped instead of wait()

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

1 comment

0

Damn it!

This discussion is preserved as it was. New answers, comments, and votes are closed.