Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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:

UIS = game:GetService("UserInputService")
Part = workspace.SpaceBar

function ChangeSpace(InputObject)
    if InputObject.KeyCode == Enum.KeyCode.Space then
        Part.Position = Vector3.new(-53.7, 21, 22.4)
		wait(0.1)
		Part.Position = Vector3.new(-53.7, 21.5, 22.4)
    end
end

UIS.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.

4 comments

1

Soo... what's wrong with your current code?

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).

1

Redbull, there was no error! It was perfectly fine! The only problem was he left his script disabled!

0

Don't worry Red, I called myself stupid. :D

1 answer

✓ Accepted answer
UIS = game:GetService("UserInputService") --The Service
Part = workspace.SpaceBar --Part
debounce = false --Debounce to prevent spamming

UIS.InputBegan:connect(function(key, a) --Function
	if key.KeyCode == Enum.KeyCode.Space and not a and not debounce then --If pressed and debounce is false and a is false then...
		debounce = true --Debounce is true
		Part.CFrame = CFrame.new(-53.7, 21, 22.4) --Change Part's CFrame
		wait(.1) --Wait .1 seconds
		Part.CFrame = CFrame.new(-53.7, 21.5, 22.4) --Change Part's CFrame
		debounce = false --Debounce is false
	end --finished
end)

Hope it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.