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

Need help with getting humanoids name from part?

Asked by 5 years ago
Edited 5 years ago

I'm trying to change a string value to the players name that touches a certain part?

(03:12:02.299 - Workspace.Arenas.Arena1.CoreParts.Pad1.Script:8: bad argument #3 to 'Value' (string expected, got Object))

script.Parent.Touched:connect(function(HumanPart)
    wait(0.1)
    local h = HumanPart.Parent:FindFirstChild("Humanoid")
    if h then
        if script.Parent.PlayerReady.Value == 1 then
            print("Player On")
            script.Parent.BrickColor = BrickColor.new("Bright red")
            script.Parent.PlayerNameOne.Value = h.Parent
            script.Parent.PlayerReady.Value = 2
        end
    end
end)
0
If my answer helped then it would be great if you could upvote/accept it! thebayou 441 — 5y
0
Won't line 4 pass as true even if h is nil? Don't you need if h~= nil then? Phantom1996 45 — 5y

1 answer

Log in to vote
0
Answered by
thebayou 441 Moderation Voter
5 years ago

I'm just going to ignore how your script violates so many practices, and just give you the answer:

on Line 08, change that to

script.Parent.PlayerNameOne.Value = h.Parent.Name

Because you're trying to set the value of something to an object when in reality it has to be the NAME of the object.

0
Thanks man! Just realised how stupid I am. retrobricks 162 — 5y
0
Nah it's no problem- part of the learning process ya know? thebayou 441 — 5y
Ad

Answer this question