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

How do you locate an item based on a value? [closed]

Asked by 8 years ago
Edited 8 years ago

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
0
HA DANZ, 2 MONTHS AGO U WERE A TOTAL NEWBIE EzraNehemiah_TF2 3552 — 8y
0
thanks rebot333 40 — 8y
0
@LordDragonZord SHT UP D: xD DanzLua 2879 — 8y
View all comments (2 more)
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. EzraNehemiah_TF2 3552 — 8y
0
ok rebot333 40 — 8y

Locked by EzraNehemiah_TF2, Link150, and Azmidium

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 8 years ago

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!

Ad