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

How do I get the value of an ObjectValue?

Asked by
acecateer 130
10 years ago

So I've been trying to make killstreaks for my game but every time I try to get the value of creator from the humanoid of the player that dies it comes up with this error:

20:01:55.010 - Workspace.OnDeath:34: bad argument #2 to '?' (string expected, got userdata) 20:01:55.011 - Script 'Workspace.OnDeath', Line 34 20:01:55.012 - Stack End

And this is the part of the script in which the error is happening:

Game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        plr:WaitForChild("Data"):WaitForChild("Morph") wait(0)
        if plr.TeamColor ~= Game.Teams.Lobby.TeamColor then
            Game.Workspace:FindFirstChild(plr.Data.Morph.Value):Invoke(plr.Character)
            Game.ServerStorage.Weapons:FindFirstChild(plr.Data.Morph.Value):Clone().Parent = plr.Character
            local HealthManager = script.HealthManager:Clone()
            HealthManager.Parent = plr.Character:FindFirstChild("Humanoid")
            HealthManager.Disabled = false
            local Killstreak = Instance.new("IntValue", plr.Character)
            Killstreak.Name = "Killstreak"

            print(plr.Character:FindFirstChild("Killstreak"))

            plr.Character.Humanoid.Died:connect(function()
                print("Person died")
                if plr.Character.Humanoid:FindFirstChild("creator") then
                    creat = plr.Character.Humanoid:FindFirstChild("creator")
                    local killer = game.Players[creat.Value]
                    print(killer)
0
Use Lua Text Box. HexC3D 830 — 10y
0
Oh, sorry about that. acecateer 130 — 10y
0
Hmm.. Can you post the whole script, not to bother you. HexC3D 830 — 10y
0
I'll only put the parts that relate to the question. acecateer 130 — 10y
0
Mk. HexC3D 830 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

creat is a ObjectValue, yet you are trying to use it as a the index on Players.

I don't remember what the value of the creator tag usually is, but from that value, you need to find the Player object. You can do that using one of these thing's:

  • The Character's name or the Player's name
  • The Character model and game.Players:GetPlayerFromCharacter
  • A reference to the player itself

Using name, it would simply be game.Players[playerName] where playerName would probably be defined as either creat.Value.Parent.Name or creat.Value.Name.

Using the character model, probably one of game.Players:GetPlayerFromCharacter(creat.Value) or game.Players:GetPlayerFromCharacter(creat.Value.Parent).

Or, if it is the player itself, just creat.Value would reference the player.

0
You're so helpful man. acecateer 130 — 10y
Ad

Answer this question