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

How do you locate an item based on a value?

I'm creating a game, and I have a StringValue that detects who it belongs to. That works fine, but I try to locate the player based on that value, and it doesn't work. I don't know how to do this, and here is my failed attempt:

while 2 > 1 do
	script.Parent.Name = game.Players[script.Parent.Owner.Value].PlayerGui.Rename.Gui.Name.Value
	wait (0.5)
end

6 comments

0

HA DANZ, 2 MONTHS AGO U WERE A TOTAL NEWBIE

0

thanks

0

@LordDragonZord SHT UP D: xD

0

Please don't put "[CLOSED]" after the question title. The moderator's job is the close questions. You shouldn't put the closed tag in your question if it isn't closed.

0

ok

1 answer

✓ Accepted answer

Use the Changed event and connect it to a function instead of making a loop.

Also, the ObjectValue has already linked the instances from game, so you can just keep linking from there.

Here is the edited script:

script.Parent.Owner.Changed:connect(function() 
    local player = script.Parent.Owner.Value
    if player ~= nil then --Makes sure the value is not nil, or else the script will crash/error!
        script.Parent.Name = player.PlayerGui.Rename.Gui.Name.Value
    end
end)

If you have any problems, please leave a comment below. Thank you and I hope this will help you!

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