hello can anyone or anybody could explain or help me how to use isKeyDown on UserInputService
ive been searchin on google and looking on the yt and i dont see or understand it.
TYSM in Advance
hello can anyone or anybody could explain or help me how to use isKeyDown on UserInputService
ive been searchin on google and looking on the yt and i dont see or understand it.
TYSM in Advance
Simple:
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
print("E key was pressed")
end
end)
Hope this helped.
Also the IsKeyDown() can be used like what this page says:
i dont see isKeyDown()
what i mean is how to use IsKeyDown()
like when the key has been hold it will fill the water and if its been released the water will stop filling
but ive learn something from you =)
Oh you can use InputBegan and InputEnded.
local KeyDown = false
InputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
KeyDown = false
end
end)
InputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
KeyDown = true
repeat
wait()
-- function here like adding 10+ to water value
until KeyDown == false
end
end)
Hope this helped aswell…
let me test it =)
i hope it helps
it didnt work =(
local KeyDown = false
local InputService = game:GetService("UserInputService")
local water = game.Workspace.Water.Size
InputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
KeyDown = false
end
end)
InputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
KeyDown = true
repeat
wait(1)
water.Y = water.Y + 5
until KeyDown == false
end
end)
You can’t do
local water = game.Workspace.Water.Size
It would just be a vector3 value of the water’s size and wouldn’t affect its size when it is changed
how do i do it??
help me im new at scripting
Try this
local KeyDown = false
local InputService = game:GetService("UserInputService")
local water = game.Workspace.Water.Size
InputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
KeyDown = false
end
end)
InputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
KeyDown = true
repeat
wait(1)
water.Y = water.Y + 5
game.Workspace.Water.Size = water
until KeyDown == false
end
end)
Alternatively you can redefine water
.
local water = game.Workspace.Water
and then when you are wanting to change the size,
water.Size = water.Size + Vector3.new(0, 5, 0)
IsKeyDown returns a boolean based on if the Enum code you pass is currently being held down. You can check already on the IsKeyDown documentation page for information about what it is and how to use it. If you actually searched, surely you should’ve come across this page, no?
You’ve got an XY Problem going here though. You always want to ask about your actual use case, not about a function and try brute forcing it into your solution. You only later stated your use case which is to have something increase as a key is held down. You do not need IsKeyDown here.
owwwwwww thx for the information =)