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

Can I tag a player without using Local Script?

I have an NPC that I want to give xp to a player upon its death. Sadly, I cant seem to tag the player who kills it with a normal script, but the npc wont work in a local script, any ideas?


local Target = script.Parent.Target
local enemy = script.Parent.Parent
local RS = script.Parent["Right Shoulder"]
local LL = script.Parent["Left Hip"]
local RL = script.Parent["Right Hip"]
Punching = false

function Walk(Part)
	 if enemy.Humanoid.Sit == true then
		enemy.Humanoid.Sit = false
	end
	for repititions = 1, 20 do
	for pose1 = 1,10 do
		LL.C0 = LL.C0 *CFrame.Angles(0, 0, 0.1)
		RL.C0 = RL.C0 *CFrame.Angles(0, 0, 0.1)
		wait(0.1)
	end
	
	for pose2 = 1,10 do
		LL.C0 = LL.C0 *CFrame.Angles(0, 0, -0.1)
		RL.C0 = RL.C0 *CFrame.Angles(0, 0, -0.1)
		wait(0.1)
	end
	end
	
end


function Chase(Part)
	if Part.Parent:FindFirstChild("Humanoid") ~= nil then
		Target.Value = Part.Parent.Name
		for chasing = 1,400 do
			if chasing == 10 or chasing == 20 or chasing == 30 or chasing == 100 or chasing == 130 or chasing == 200 then
				
				 local x = Instance.new("Part")
       			 x.BrickColor = BrickColor.new("White")
       		 x.Material = "Neon"
       		 x.CanCollide = false
       		 x.Transparency = 0.6
       		 x.Size = Vector3.new(8,8,8)
       		 x.TopSurface = "Smooth"
       		 x.BottomSurface = "Smooth"
       		 x.Shape = "Ball"
       		 x.Parent = Workspace
             local fd = script.fireDamage:clone()
             fd.Parent = x


             local a = Instance.new("Sound")
        a.SoundId = "http://www.roblox.com/asset/?id=260430117"
        a.Parent = x
        a.Volume = 2
        a.Pitch = 1.3
        a:play()
        local effect = game.ServerStorage.Effects.NpcPunch1.Effect:clone()
        effect.Parent = x
        local light = game.ServerStorage.Effects.NpcPunch1.Light:clone()
        light.Parent = x

        local y = Instance.new("BodyVelocity")
        y.maxForce = Vector3.new(math.huge ,math.huge ,math.huge)
        y.velocity = enemy.Torso.CFrame.lookVector*115

        x.CFrame = enemy.Torso.CFrame*CFrame.new(0, 1 , -10)
        x.Parent = Workspace
        y.Parent = x    
        game.Debris:AddItem(x, 6)


			end
			if Punching == false then
			enemy.Humanoid:MoveTo(Part.Parent.Torso.Position,Part.Parent.Torso)
			end
			wait(0.5)
		end
	
	end
end



function Punch(Part)
	if Punching == false and Part.Parent:FindFirstChild("Humanoid") ~= nil then 
		Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health - 60
		local v = Instance.new("BodyVelocity")
		game.Debris:AddItem(v, 1)
		Part.Parent.Humanoid.Sit = true
		v.Parent = Part.Parent.Torso
		v.Velocity = enemy.Torso.CFrame.lookVector *50
		v.maxForce = Vector3.new(math.huge, math.huge, math.huge)
		Punching = true
		for RSLOOP = 1,10 do
	  	  RS.C0 = RS.C0 * CFrame.Angles(0, 0, 0.25)
	   	  wait(0.1)
		  end
		for RSLOOP = 1,10 do
	  	  RS.C0 = RS.C0 * CFrame.Angles(0, 0, -0.25)
	   	  wait(0.1)
		   end
		Punching = false
	end
end


script.Parent.Touched:connect(Punch)
script.Parent.Touched:connect(Chase)
script.Parent.Touched:connect(Walk)

3 comments

0

Just looking at the length of the script, a majority of people won't take the time to even look. State the line numbers where you need help.

0

You actually can tag the player who killed it with a normal script. Use a RemoteEvent to create the tag on the server.

0

I don't need help in a certain part of the script, it's just there incase someone needed to look it over to help. And I'll be sure to check into using a RemoteEvent, thanks!

1 answer

✓ Accepted answer

LocalScripts are meant to run on the Client, where-as Scripts are to run on the Server. Since the NPC is controlled by the server (not any one player), that is why it won't work in a LocalScript.

What you need to do is figure out how to tell who killed the NPC. The way Roblox weapons at least used to do this (and I think they still do) is using 'tags'. Every time a weapon is used, it will tag the humanoid for a moment, so that if the humanoid dies, server scripts will know who was responsible. (The LocalScripts responsible for the weapons will have to communicate with the server to apply the tag.) Of course, you need a script that monitors the humanoid for death and takes the appropriate action (you'll need the Humanoid.Died event) as well.

Another option is to simply aware all characters that are within range. Though this will also give people who did nothing XP, it might be better if:

  • You can't figure out how to make all your weapons tag the NPC humanoid temporarily
  • You have a cooperative game rather than solo

In this method, when the humanoid dies you simply take a look at who is nearby (maybe their Character's Torso is within 15 studs or something). Be sure to check values for nil before using them (as you should always do) - for example, don't assume that a character's Torso exists before using FindFirstChild to confirm that it is there. Failure to do so may break your script (meaning no one will get XP) in certain (sometimes rare) situations.

For the best results, you might want to combine both approaches - apply tags to the humanoid that stay there for multiple seconds (maybe even up to 10), and award XP to all people who have a tag on the humanoid when it dies. That way, everyone who recently did damage to the humanoid will get rewarded.

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