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

Why can't my script make the part's position go down when I hit spacebar?

Asked by 10 years ago

I am making a script where when I hit spacebar, it makes the part go down by 0.5 of the Y position. This is the script from what I am trying to do:

01UIS = game:GetService("UserInputService")
02Part = workspace.SpaceBar
03 
04function ChangeSpace(InputObject)
05    if InputObject.KeyCode == Enum.KeyCode.Space then
06        Part.Position = Vector3.new(-53.7, 21, 22.4)
07        wait(0.1)
08        Part.Position = Vector3.new(-53.7, 21.5, 22.4)
09    end
10end
11 
12UIS.InputBegan:connect(ChangeSpace)

This script is actually from Redbullusa for when he answered my previous question. And so I changed it a little to something I am working on. I want it where if I hit spacebar, the part for it will go down and within 0.1 seconds, it goes back up to normal.

1
Soo... what's wrong with your current code? Goulstem 8144 — 10y
2
That's a valid code. It's just that it's probably too quick for you to see while you're jumping (if you are). Redbullusa 1580 — 10y
1
Redbull, there was no error! It was perfectly fine! The only problem was he left his script disabled! EzraNehemiah_TF2 3552 — 10y
0
Don't worry Red, I called myself stupid. :D RobotChitti 167 — 10y

1 answer

Log in to vote
3
Answered by 10 years ago
01UIS = game:GetService("UserInputService") --The Service
02Part = workspace.SpaceBar --Part
03debounce = false --Debounce to prevent spamming
04 
05UIS.InputBegan:connect(function(key, a) --Function
06    if key.KeyCode == Enum.KeyCode.Space and not a and not debounce then --If pressed and debounce is false and a is false then...
07        debounce = true --Debounce is true
08        Part.CFrame = CFrame.new(-53.7, 21, 22.4) --Change Part's CFrame
09        wait(.1) --Wait .1 seconds
10        Part.CFrame = CFrame.new(-53.7, 21.5, 22.4) --Change Part's CFrame
11        debounce = false --Debounce is false
12    end --finished
13end)

Hope it helps!

Ad

Answer this question