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

[UDim2] Add Poisition: [KeyDown/Held] {GUIs} Help?

Would there be a way to make this to add a position when its held down? :D

Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
mouse.KeyDown:connect(function(key)
        if key == "q" then
            script.Parent.Position = UDim2.new(0, 1200,0, 602)
        elseif key == "e" then
            
 end       
end)        
   

1 answer

Create an empty table. Tag keys as true when they are pressed, and tag them as false when they are released. Then, use a RenderStepped (executes ~60 times per second) event to deal with the currently pressed keys

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local down = {}

mouse.KeyDown:connect(function(key)
	down[key:lower()] = true
end)

mouse.KeyUp(function(key)
	down[key:lower()] = false
end)

game:GetService("RunService").RenderStepped:connect(function()
	if down["q"] then
		--do stuff
	end
end)

3 comments

0

ForeverDev why did you take down cookie clicker?

0

ForeverDev How Would I add the Position to the player/image?

0

Output: Players.Player1.PlayerGui.ScreenGui.Mario.Script:6: attempt to index upvalue 'down' (a nil value)

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