script.Parent.Touched:Connect(function(V)
if V.Parent:FindFirstChild("Trian") then
print("TrainWasFound")
V.Parent.Main.BodyVelocity.Velocity.X = -5
end
end)
COMMUNITY QUESTION
How to change body velocity with a script?
1 answer
The positional components of a Vector3 are immutable, meaning that you can't edit the properties directly or it'll return an error. You will have to create a new vector with the new X component:
script.Parent.Touched:Connect(function(V)
if V.Parent:FindFirstChild("Train") then
print("TrainWasFound")
local vel = v.Parent.Main.BodyVelocity.Velocity
V.Parent.Main.BodyVelocity.Velocity = Vector3.new(-5, vel.Y, vel.Z)
end
end)
At least try to include some context of the issue you're having, how you intended to behave and any error(s) in your questions
This discussion is preserved as it was. New answers, comments, and votes are closed.
