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

How to make a value that shows the username of an occupant of a seat?

Asked by 4 years ago
Edited 4 years ago

I'm trying to make a value that will change to the occupant's username but it isn't working. Here is the script:

user = script.Parent.Parent.VehicleSeat.Occupant
script.Parent.Value = user

3 answers

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago

user is an object, user.Name is a value, use that

user = script.Parent.Parent.VehicleSeat.Occupant
script.Parent.Value = user.Name
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

In ROBLOX, there are three different types of value instances. We have IntValues, BoolValues, and StringValues. All of these instances have different purposes. An IntValue's purpose is to store numbers so that they can later be used in a mathematical problem to keep track of the amount of something a player has (anything that has to do with amounts). A StringValue's purpose is to store strings (another word for text). If you try to make a StringValue's value 12, you can not call upon the value for a mathematical problem, as it is stored as text and not a number. The final value, BoolValues, are used to store either true or false.

Right now what you're doing is making the value of the StringValue an object (or at least attempting to). What you want to do is convert the user value to a string. This is pretty simple to do just by putting a tostring() around "user", making your script look like this:

user = script.Parent.Parent.VehicleSeat.Occupant
script.Parent.Value = tostring(user.Parent) --added.Parent because user currently gives us a humanoid and not the player.
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
4 years ago

The occupant of a seat will give you the humanoid of a character. To get the username of the character, you just need to get the parent of said humanoid.

We are going to bind an update function, so that when the occupant changes, the string value will update.

We are also going to add checks, to make sure that the code does not error

Going off what cmgtotalyawesome had said, we are going to use 'tostring'

local seat = script.Parent.Parent
local stringval = script.Parent

local function update()

    wait()

    local user = script.Parent.Parent.Occupant
    if user ~= nil then --checks to prevent any errors
        stringval.Value = tostring(user.Parent) --grabs the parent of the humanoid
    else
        print("nil") --no one is currently in the seat
    end 

end

seat.Changed:Connect(update)

Answer this question