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

Im making a script that makes a part move up when it is clicked but i'm having trouble with it?

Im making a script that makes a part move up when it is clicked! Now the part that is supposed to move isn't the scripts parent, so lets just say its parent is workspace and its name is "MovingPart"! Now this morning I found the right function but its the part of the script where the "MovingPart" actually moves up and in no other direction say 5 studs! Now I think that I could probably answer my question myself on the Roblox Wiki, but I have no idea what to search, but I am pretty sure I once knew what this is called but clearly I dont remember how too! But anyways here is the script!

function onClicked(playerWhoClicked)
    game.workspace.MovingPart.Position.Y = game.workspace.MovingPart.Position.Y + 500
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 comment

0

Vector3 Ill keep that in mind

3 answers

✓ Accepted answer

Keep in mind that Vector3 values are immutable, meaning that their component values cannot be reassigned after being initialized. Hence, you should change

game.workspace.MovingPart.Position.Y = game.workspace.MovingPart.Position.Y + 500

to

local movingPart = workspace.MovingPart
movingPart.Position = movingPart.Position + Vector3.new(0,500,0)

(I created a variable to save space)

1 comment

0

Thanks! It helps alot

Just don't use .Y just use Vector3.new(0, number, 0)

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