Ad
Log in to vote
-1

Why won't my Velocity Script work? Again...

Asked by 7 years ago

Hello! After some testing and trial and error, I have come up with this script with a little help from last time. i am attempting to have a gui frame pop up when the player goes at a speed of -210 downwards. (or Y) However When I test it, this comes up in the output: 15:39:21.548 - Workspace.Player.LocalScript:3: attempt to compare two userdata values I don't quite understand this. Here is the script

s = script.Parent
while true do
        if game.Players.LocalPlayer.Character:FindFirstChild("Torso").Velocity <= Vector3.new(CurrentXValue,-210,CurrentZValue) then
    game.Players.LocalPlayer.PlayerGui.BlackoutGUI.Frame.Visible = true
    else
        game.Players.LocalPlayer.PlayerGui.BlackoutGUI.Frame.Visible = false
    end
end

NOTE! i have a script that inserts this local script into the player already so all I need his help with this one.

Thank you! I hope I can get an analysis of what I am doing wrong!

~Minikitkat

2 answers

Log in to vote
1
Answered by
BlueTaslem 18066 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

A userdata value is a C object, or, in other words, some ROBLOX object.

Userdata include ROBLOX instances, CFrames, BrickColors, Color3s, and Vector3s.

For technical reasons, Lua is unable to report which type of ROBLOX object something is in an error -- only report that it is indeed a userdata (hence the not-so-clear error message)


In this case, it is a Vector3 values (.Velocity and Vector3.new(...)). You're trying to compare (using less than or equal to, <=) them.

You can't meaningfully compare vector3s -- there's no way to say one position in space is "bigger" than another (math can show this more rigorously).


Since you're interested in comparing the .y value, just do that instead:

if Torso.Velocity.y <= -210 then

You type out game.Players.LocalPlayer 3 times in your script. At that point, I would definitely suggest you make a variable to save yourself issues from having to type out something long (and/or mis-type something long), e.g.,

local player = game.Players.LocalPlayer

toward the top of your script.

1
Yay! This worked!!! Thank you! minikitkat 687 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

You should keep in mind that while loops should have a wait() to avoid the client from crashing.

Answer this question