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

How to turn an Instance into a String?

Asked by 1 year ago

So I want to get the players name when triggering the function and change the parts name into the players, but when I try to do that it returns an error:

Unable to assign property Name. string expected, got Instance

Code:

interact.Triggered:Connect(function(player)
    local randomitem = item[math.random(1, #item)] 
    print(randomitem)

    if randomitem == Garbage1 then
        local gCopy1 = Garbage1:Clone()
        gCopy1.Parent = workspace
        gCopy1.Name = player
    end
end)

Of course the parts name cannot be an Instance, but I have no other idea how to do it so I'm wondering if you could turn an instance into string?

1 answer

Log in to vote
0
Answered by 1 year ago

You forgot to add player.Name, you just did player. The solution should be this:

interact.Triggered:Connect(function(player)
    local randomitem = item[math.random(1, #item)] 
    print(randomitem)

    if randomitem == Garbage1 then
        local gCopy1 = Garbage1:Clone()
        gCopy1.Parent = workspace
        gCopy1.Name = player.Name
    end
end)

As always, tell me if you encounter any issues.

Ad

Answer this question