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

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

Asked by 6 years ago

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?

0
You cannot change an x,y or z alone, you have to change the whole number User#20388 0 — 6y

1 answer

Log in to vote
0
Answered by
wind_o 15
6 years ago

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

Answer this question