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 6 years ago
Edited 6 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) :

01local tool = script.Parent
02local candamage = tool:WaitForChild("CanDamage")
03local player = game.Players.LocalPlayer
04 
05tool.Blade.Touched:connect(function(p)
06    local char = p.Parent
07    local hum = char:FindFirstChild("Humanoid")
08    local hitsound = tool:WaitForChild("Hit")
09if candamage.Value == false then
10    if hum then
11            candamage.Value = true
12            hitsound:Play()
13            hum.Health = hum.Health - script.Dmg.Value
14            wait(1)
15            candamage.Value = false
View all 21 lines...

the one inside the npc (using script):

1local human = script.Parent:WaitForChild("Humanoid")
2human.Died:connect(function()
3    local tag = human.Parent:FindFirstChild("creator")
4    if tag then
5game.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
6    end
7end)

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 — 6y
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 — 6y
0
your making local tag = Instance.new("StringValue",p.Parent.Humanoid) have a parent early cherrythetree 130 — 6y
View all comments (7 more)
0
Also instead of hum.Health = hum.Health - script.Dmg.Value, use hum:TakeDamage(script.Dmg.Value) cherrythetree 130 — 6y
0
@TheluaBanana thats what im trying to ask RichardP965 2 — 6y
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 — 6y
0
@RichardP965 good job u dont even know how to do that TheluaBanana 946 — 6y
0
its ok well get there step by step TheluaBanana 946 — 6y
0
@TheluaBanana Can you teach me how to do that correctly? RichardP965 2 — 6y
0
k i gave a easy enough way TheluaBanana 946 — 6y

2 answers

Log in to vote
0
Answered by 6 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 — 6y
0
no its meant to be the first step. TheluaBanana 946 — 4y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

u changed

1local char = p.Parent

u need change it to

1local char = p.Character

instead of Parent

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

Answer this question