How do I add Creator Tags for my gun?

Hello, I am currently having trouble finding a way to add creator tags to my guns that I made. I could really use help.

Local Script in gun:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent

local Cooldown = false
local COOLDOWN_TIME = 0.5

local function Pew()
	Tool.Handle.PointLight.Enabled = true
	game.ReplicatedStorage.ShootGun:FireServer(Mouse.Hit.p, Tool.Handle)
end

local function Shoot()
	
	if Cooldown == true then
		return
	end
	
	Cooldown = true
	Pew()
	
	print("SHOOTING")
	
	wait(COOLDOWN_TIME)
	Cooldown = false
	Tool.Handle.PointLight.Enabled = false
end

Tool.Activated:Connect(function()
	
	Shoot()
	
end)

Script in server script service:

local RANGE = 525
local DAMAGE = 20

game.ReplicatedStorage.ShootGun.OnServerEvent:Connect(function(Player, TargetLocation, Handle)
	if Player.Character == nil then
		return
	end
	
	Handle.Sound:Play()
	
	local Beam = Instance.new("Part", workspace)
	Beam.BrickColor = BrickColor.new("New Yeller")
	Beam.FormFactor = "Custom"
	Beam.Transparency = 0.25
	Beam.Material = "Neon"
	Beam.Anchored = true
	Beam.CanCollide = false
	
	
	local Distance = (Handle.Position - TargetLocation).magnitude
	Beam.Size = Vector3.new(0.1, 0.1, Distance)
	Beam.CFrame = CFrame.new(Handle.Position, TargetLocation) * CFrame.new(0, 0, -Distance/2)
	
	game.Debris:AddItem(Beam, 0.1)
	
	local NewRay = RaycastParams.new()
	local RayDirection = (TargetLocation - Handle.Position) * RANGE
	
	NewRay.FilterDescendantsInstances = {Player.Character}
	
	local Result = workspace:Raycast(Handle.Position, RayDirection, NewRay)
	
	if Result then
		if Result.Instance then
			
			if Result.Instance.Parent:FindFirstChild("Humanoid") then
				Result.Instance.Parent.Humanoid.Health -= DAMAGE
			end
		end
	end
end)
3 Likes

Could you elaborate on what you mean by a Creator Tag?

1 Like

Damage tag, like what the linked sword does.
Copied code from the linked sword:

local Debris = game:GetService("Debris")

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

When they damage someone they use the functions in the following order:

UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)

Basically do the exact same when you damage someone.

3 Likes

If I’m interpreting what @KJry_s mentioned

You could impliment this

			if Result.Instance.Parent:FindFirstChild("Humanoid") then
				Result.Instance.Parent.Humanoid.Health -= DAMAGE
				local CT = Instance.new("ObjectValue", Result.Instance.Parent.Humanoid)
				CT.Name = "Creator"
				CT.Value = Player
				
				game.Debris:AddItem(CT,2)
			end
2 Likes

I’m having the same issue with a ray gun I modeled. Funny thing is that the creator tag in my swords and hubs will give me EXP for kills. But the creator tag will not do the same for my ray gun.

1 Like

*guns,3333333333333333, ooooooooooooo

1 Like

Actually the script provided by @KJ worked for me. I inserted the code in the wrong script. Now I can track kills and EXP.

Thanks,

1 Like