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)
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:
game.Players:GetPlayerFromCharacter
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.