I am making a game where you kill NPC. but i can not figure out how to write this.(The script is to give gold to me when i kill an npc) Located in startergui:
local player = script.Parent.Parent local leaderboard = player:WaitForChild("leaderstats") local currency1 = leaderboard:WaitForChild("Gold") function onDied() print("Dead") currency1.Value = currency1.Value + 100 end script.Parent.Parent.Workspace.TutPrac.Viking.Humanoid.Died:connect(onDied)
Thanks!
Its usually better to put the localscript into the Tool of the sword.
Try using a sword and use this script. (Put it into the tool)
Use this link to learn how to make a sword if you dont know. (Also needed for the "Hitmark" part in the script: How to make a sword
local hitmark = script.Parent.hitname --Let this be the part that damages the player --(May need to watch the tutorial provided above) local player = game.Players.LocalPlayer local leaderstats = player:WaitForChild("leaderstats") hitmark.Touch:connect(function(npc) if npc.Parent.Name == "Viking" and npc.Parent.Humanoid.Health == 0 then -- Checks if the NPC killed is named Viking and checks if dead leaderstats.Currency.Value = leaderstats.Currency.Value + 50 -- Adds currency end end)
Im not that professional at scripting but this is what I know. Use the Output of any errors. If the output does not help however, it may give you an idea on what to do.