OK. So. There have been multiple discussions I put out that talked about where when i killed something +1 soul would be added to the leader board. (The leader board that when you click tab opens up). Though. I have made a new script that hopefully makes sense.
Its a normal script btw:
local Shep = workspace.Shep:FindFirstChild("Humanoid")
local player = workspace.Players:FindFirstChild("Humanoid")
local health = workspace.Shep.Humanoid.Health
local leaderstats = workspace.ServerScriptService:FindFirstChild("leaderstats")
while health > 0 do
if health <= 0 then
leaderstats.Souls.Value +=1
Shep:Destroy()
end
end
Hopefully this makes sense.
There is quite a lot of things that need to be fixed in the script for it to run, so it would be best to describe the situation more and how you got to this point. Where do you want this script to exist?
Ok so the script is under the object “Shep”
Try referencing the humanoid instead of a property, changing the loop condition to “humanoid.Health <= 0”, removing the if statement and breaking the loop so it doesn’t keep increasing the value.
Also did you mean “game” instead of “workspace” on line 4?
local Shep = workspace.Shep:FindFirstChild("Humanoid")
local player = workspace.Players:FindFirstChild("Humanoid")
local humanoid = workspace.Shep.Humanoid
local leaderstats = workspace.ServerScriptService:FindFirstChild("leaderstats")
while humanoid.Health <= 0 do
leaderstats.Souls.Value +=1
Shep:Destroy()
break
end
Ya I meant to put game on line 4
Though it still doesn’t work
This script has a LOT of problems. I will list all the problems right below:
You cannot get players from workspace just like that. ServerScriptService is not in workspace, its a separate service. You are also getting the leaderstats script in ServerScriptService, not the folder. The leaderstats folder is in every player object. If this script is under Shep, then mention script.Parent instead of finding it from workspace. Instead of constantly checking the health of the Shep, you can use object values to detect who is damaging the Shep.
1 Like
Here is a possible rewrite of your script, assuming it is a script that is inside of an NPC.
local shep = script.Parent
local shepHumanoid = shep:WaitForChild('Humanoid')
while true do
-- The Health property needs to be indexed at this moment, and not assigned to a variable before-hand
if shepHumanoid.Health <= 0 then
break
end
-- The loop needs a wait or some kind of yield
wait()
end
local playersService = game:GetService('Players')
local player = playersService:FindFirstChildOfClass('Player') -- Grabs the first arbitrary player.
if player then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local souls = leaderstats:FindFirstChild('Souls')
if souls then
souls.Value = souls.Value + 1
end
end
end
shep:Destroy()
3 Likes
The script worked! thanks! Honestly though. I’ve been working on this script for 3 days and you helped me so much with your rewrite!!!
1 Like