Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To Make The Hostile NPC Recognize and gives exp to the killer?

Asked by 5 years ago
Edited 5 years ago

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?

0
Does you game use FE ? If yes the first script (in the weapon) should be a local script because Players.LocalPlayer can't be accessed with a regular script. And you should use remote event/function to spawn the tag. xJathur95x 129 — 5y
0
kid make the npc remember the person that last hit it, then once the npc dies award points to the player. this encourages competition in the game. TheluaBanana 946 — 5y
0
your making local tag = Instance.new("StringValue",p.Parent.Humanoid) have a parent early cherrythetree 130 — 5y
View all comments (7 more)
0
Also instead of hum.Health = hum.Health - script.Dmg.Value, use hum:TakeDamage(script.Dmg.Value) cherrythetree 130 — 5y
0
@TheluaBanana thats what im trying to ask RichardP965 2 — 5y
0
@xJathur95x Roblox Forced FE on all games on 2018 and thx for the suggestion to ill try to make it that way RichardP965 2 — 5y
0
@RichardP965 good job u dont even know how to do that TheluaBanana 946 — 5y
0
its ok well get there step by step TheluaBanana 946 — 5y
0
@TheluaBanana Can you teach me how to do that correctly? RichardP965 2 — 5y
0
k i gave a easy enough way TheluaBanana 946 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
  1. place string value inside npc

  2. 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

  3. 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?

0
yea its thanks but i don't understand the (1.) is it meant to be the first script? RichardP965 2 — 5y
0
no its meant to be the first step. TheluaBanana 946 — 4y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

u changed

local char = p.Parent

u need change it to

local char = p.Character

instead of Parent

0
pppppp TheluaBanana 946 — 5y
0
But its not for a Player Can it work with Non-Playable Character? RichardP965 2 — 5y

Answer this question