What I am trying to do is find the player when the mob is killed and add xp to that player. This is what I've tried so far:
local mob = script.Parent --//Enemy mob.Touched:connect(function(p) --// When the mob is touched, this function will fire. (p = player who touched. local actp = p.Parent --// The object that touches will most likely be a body part so get its parent. local newp = game.Players:FindFirstChild(actp.Name) --// Find the parents name. local stats = newp:WaitForChild('leaderstats') --//Get its stats. local EXP = stats:WaitForChild('EXP') --//Get the stat to reward to. if mob.Humanoid.Health == 0 then --Basically first person to touch it after it dies gets the reward (not what I'm looking for.) EXP.Value = EXP.Value + 20 --//Reward EXP. end end)
What I am trying to do is to find the player who killed the mob, get that players stats and add to the xp.
(I know how to add the reward just need to get the player who killed the mob)
Well to get a player in a Touched Event
most like what you're using you could use this line of code to set a Variable
for the Player
....
local player = game.Players:GetPlayerFromCharacter(actp)
That's basically it.
Now the variable "player" is referring the Player
of the Character
that touched the object....
Oh, P.S you might want to make sure that the Part
that touches it is a Character's
part..... So you could put this following line of code on top so it checks for the Character
before running anything in the script... Or else your script will break.... If you don't check for the Character
.
local phumanoid = p.Parent:findFirstChild("Humanoid") if phumanoid then
My guess is you're working on SAO.