Part = script.Parent BodyVelocity = Part.BodyVelocity L = 'Touchpart' Part.Touched:Connect(function(hit) if hit:FindFirstChild('StringValue').Value == 'RevertValue' then Neg = hit:FindFirstChild('Negative') Pos = hit:FindFirstChild('Positive') if BodyVelocity.Velocity < Pos.Value then BodyVelocity.Velocity = Neg.Value elseif BodyVelocity.Velocity > Neg.Value then BodyVelocity.Velocity = Pos.Value end end end)
it keeps saying 14:22:46.050 - Workspace.Part.Script:9: attempt to compare userdata with number
14:22:46.050 - Workspace.Part.Script:9: attempt to compare userdata with number
14:22:46.050 - Workspace.Part.Script:9: attempt to compare userdata with number
I don't get why and what a user data is and why its erroring any fix
The Velocity
property from the BodyVelocity object is a Vector3
userdata type. Userdata types include CFrame or BrickColor. I'm assuming that "Positive" is a NumberValue object, so technically you're comparing something that looks like:
if Vector3.new(0, 0, 0) < 123 then --example case
To fix this you could compare Positive.Value
, and the other, to the read-only properties of the Vector3. So something like:
if BodyVelocity.Velocity.Y < Pos.Value then --run code if Y value is lower elseif BodyVelocity.Velocity.Y > Pos.Value then --run code if Y value is greater end
The top is just an example at what you're looking for. You do have access to the other immutable properties for a Vector3. You can see a list of them here.