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

Humanoid touches a part so that different part's velocity changes to 0, doesn't work. Help?

So I've been scripting and I'm making a Roblox Ninja Warrior, I'm using the velocity cause it's a good friend of mine and I want to make it turn to 0 when a humanoid touches a part.

Script:

function OnTouched(hit)
	script.Parent.Parent.Thingy.Velocity.X=0
end

script.Parent.Touched:connect(OnTouched)

I've been doing Vector3 (Error told me) but it still didn't work so I did this. Still doesn't work! Roblox shows me this when I touch the part:

X cannot be assigned to

Idk wth I gotta do. Anyone tell me what to do and/or fix my script?

1 comment

0

You cannot change an x,y or z alone, you have to change the whole number

1 answer

✓ Accepted answer

You can not write to one property of a Vector value (the same goes for UDim2s, and it's a pain tbh). You have to create a new one entirely.

Example with your code:

function OnTouched(hit)
local currentVelocity = script.Parent.Parent.Thingy.Velocity
local newVelocity = Vector3.new(0,currentVelocity.Y,currentVelocity.Z)
script.Parent.Parent.Thingy.Velocity = newVelocity
end
 
script.Parent.Touched:Connect(OnTouched)

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