GeckocoJoin Date: 2014-09-28 Post Count: 536 |
I am trying to do x=something with a gui where you press w the sprite moves up.
My script: for Key="w" do script.Parent.chatFrame.chatFrame.Sprite.Position=script.Parent.chatFrame.chatFrame.Sprite.Position-UDim2.new(0,0 , .01,0) end
I love JSON! (Nope I hate it...) |
|
GeckocoJoin Date: 2014-09-28 Post Count: 536 |
Woops old code: new code
#Code while Key=="w" do wait() script.Parent.chatFrame.chatFrame.Sprite.Position=script.Parent.chatFrame.chatFrame.Sprite.Position-UDim2.new(0,0 , .01,0) end
I love JSON! (Nope I hate it...) |
|
|
Key probs isn't defined in the script, nor does it equal w.
Try (in a locascript):
#Code local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Sprite = script.Parent.chatFrame.chatFrame.Sprite
Mouse.KeyDown:connect(function(key)
if(key == "w")then
Sprite.Position = Sprite.Position - UDim2.new(0, 0, .01, 0)
end
end) |
|
GeckocoJoin Date: 2014-09-28 Post Count: 536 |
It is called its within a function I know what im doing. Just the new script will make it go forever up
I love JSON! (Nope I hate it...) |
|
|
|
Basically this is what you are looking for
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.W then
script.Parent.chatFrame.chatFrame.Sprite.Position=script.Parent.chatFrame.chatFrame.Sprite.Position-UDim2.new(0,0 , .01,0)
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress) |
|
GeckocoJoin Date: 2014-09-28 Post Count: 536 |
Yeah I had got that. I am looking for when the key is pressed and held down the sprite will move up.
I love JSON! (Nope I hate it...) |
|
GeckocoJoin Date: 2014-09-28 Post Count: 536 |
Bump
I love JSON! (Nope I hate it...) |
|
|
then yo uwant this:
mouse = game.Players.LocalPlayer:GetMouse()
holdingkey = false
mouse.KeyDown:connect(function(key)
if key == "c" then
holdingkey = true
while holdingkey do script.Parent.chatFrame.chatFrame.Sprite.Position=script.Parent.chatFrame.chatFrame.Sprite.Position-UDim2.new(0,0 , .01,0)
end
end
end
end)
mouse.KeyUp:connect(function(key)
if key == "c" then
holdingkey = false
end
end) |
|
|
oops forgot the change the c to w
here:
mouse = game.Players.LocalPlayer:GetMouse()
holdingkey = false
mouse.KeyDown:connect(function(key)
if key == "w" then
holdingkey = true
while holdingkey do script.Parent.chatFrame.chatFrame.Sprite.Position=script.Parent.chatFrame.chatFrame.Sprite.Position-UDim2.new(0,0 , .01,0)
end
end
end
end)
mouse.KeyUp:connect(function(key)
if key == "w" then
holdingkey = false
end
end) |
|
|
I think KeyDown and KeyUp are deprecated, try InputBegan/InputEnded/InputChanged
|
|
BanTechJoin Date: 2015-12-31 Post Count: 886 |
Option 1: set a variable to true, set a while variable do loop going, and set it to false when UserInputService.InputEnded is fired with key W.
Option 2:
UIS = game:GetService('UserInputService')
function checkW()
local keys = UIS:GetKeysPressed()
for _, k in pairs() do
if k.KeyCode.Name == "W" then
return true
end
end
return false
end
--inside your inputbegan handler
while checkW() do
--stuff
end |
|
|
"while holdingkey do script.Parent.chatFrame.chatFrame.Sprite.Position=script.Parent.chatFrame.chatFrame.Sprite.Position-UDim2.new(0,0 , .01,0)
end
end"
Don't you need a coroutine? |
|