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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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)
0
ForeverDev why did you take down cookie clicker? raystriker6707 30 — 10y
0
ForeverDev How Would I add the Position to the player/image? Timster111 25 — 10y
0
Output: Players.Player1.PlayerGui.ScreenGui.Mario.Script:6: attempt to index upvalue 'down' (a nil value) Timster111 25 — 10y
Ad

Answer this question