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

Is it possible to tag humanoids with a gun?

The Roblox sword has this neat script that, upon making contact with another humanoid, creates an object value in the humanoid with the value being the creator. This is a very efficient way to give cash or experience points to the attacker after killing another player. Is there any way to do this same thing with a raycast gun?

1 answer

✓ Accepted answer

Yes, Leedle it is possible!

To do this it's fairly simple! In the below script I will demonstrate a slightly different example but it should give you a grasp of how to do this!

local Part = script.Parent

local function partTouched(hit)
	if (hit.Parent:FindFirstChild('Humanoid') then --Check if whatever hit it has a humanoid
		local PlayersChar = hit.Parent --Defining PlayersChar
		local creatorVal = Instance.new('ObjectValue') --Creating an ObjectValue
		creatorVal.Name = 'Creator' --Setting the name of the new objectvalue
		creatorVal.Value = Part --setting the part as the ObjectValues value
		creatorVal.Parent = PlayersChar:WaitForChild('Humanoid') -- Lastly, setting the new ObjectValues parent to the PlayersChar humanoid
	end
end

Part.Touched:Connect(partTouched)

Keep in mind the above script is untested and was typed out from mere experience

Happy scripting!

4 comments

0

Then from another script you could get the ObjectValue from the damaged player, then proceed to change anything you'd like from the creator value!

0

This works good but is it possible for the Value to be the player (not the physical character) who is attacking? This makes it so that the bullet is the value.

0

I'm not sure about that; however, what I'd do is simple! I'd make an IntValue and just set the Value to the Players name. Then in another script, just take the Players name, find it in game.Players then get that Players object if that makes sense.

0

Gotcha, thanks for your time.

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