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

How do I get the value of an ObjectValue?

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)

5 comments

0

Use Lua Text Box.

0

Oh, sorry about that.

0

Hmm.. Can you post the whole script, not to bother you.

0

I'll only put the parts that relate to the question.

0

Mk.

1 answer

✓ Accepted answer

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.

1 comment

0

You're so helpful man.

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