Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to turn an Instance into a String?

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

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.