hello there ,
so recently im planning to make a rpg game and when testing using roblox studio play mode but im having trouble with the stats system that gives exp when a player killed a npc
the script in the weapon (using regular script and it also says the player cant be found) :
local tool = script.Parent local candamage = tool:WaitForChild("CanDamage") local player = game.Players.LocalPlayer tool.Blade.Touched:connect(function(p) local char = p.Parent local hum = char:FindFirstChild("Humanoid") local hitsound = tool:WaitForChild("Hit") if candamage.Value == false then if hum then candamage.Value = true hitsound:Play() hum.Health = hum.Health - script.Dmg.Value wait(1) candamage.Value = false local tag = Instance.new("StringValue",p.Parent.Humanoid) -- creates new value tag.Name = "creator" -- sets the name tag.Value = player.Name -- sets it to the name of the killer (i hope) end end end)
the one inside the npc (using script):
local human = script.Parent:WaitForChild("Humanoid") human.Died:connect(function() local tag = human.Parent:FindFirstChild("creator") if tag then game.ReplicatedStorage.Events.Geee:Fire(10,human.creator.Value)--gee is a bindable event so far i haven't got an error in the output but if there's a mistake please help me :( im still new to scripting end end)
it keeps saying it cant find the creator tag
i hope it can give the player 10 exp when the player kills it
Edit: I saw the comments that i should use Event to add the tag to the npc but how do i exactly do that?
place string value inside npc
when player uses a weapon or something, and if that weapon hits the npc, have the string value mentioned in (1.) set to the player's name
if npc dies have a script in it which searches thru the player list to find the player with matching name of the value, and if match is found, award player points
simple enough?
u changed
local char = p.Parent
u need change it to
local char = p.Character
instead of Parent