Hey, so I’ve been tinkering with using variables with my part, so it moves 1 stud each (ex. 1 second) whenever I hold down a certain key, but the part starts increasing every value, even though I only change 1.
I’m mainly looking for (2) answers here, how to fix my part resetting to its original value/spot, and how to fix the parts value(s) increasing exponentially, I only want 1 value to increase by 1.
Script:
wait(2)
local InputService = game:GetService("UserInputService")
local spot = game.Workspace.poerge
local KeyDown = false
local Yvalue = 0
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(0.5)
print("I thinks it work")
Yvalue += 1
game.Workspace.poerge.CFrame += Vector3.new(Yvalue, spot.Position.Y, spot.Position.Z)
-- function here
until KeyDown == false
end
end)
Video:
Note: The part will reset even if/when I am still holding E, it has no contribution to it. The part will only stop where it is if I let go of E.