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

How do you fix where a value is a child of something but the system does not see it?

Asked by 5 years ago
Edited 5 years ago

My script is supposed to give XP to a person that kills an NPC, however i've run into problems along the way.

(script i am having trouble with)

1local humanoid = script.Parent.Humanoid
2humanoid.Died:Connect(function()
3    game.ServerStorage:WaitForChild("Events").GiveXp:Fire(100, humanoid.creator.Value)
4end)

(damage script)

01script.Parent.Touched:Connect(function(hit)
02    local DmgValues = {script.Dmg.Value, script.DmgCritical.Value, script.Dmg2.Value, script.Dmg3.Value, script.DmgCritical2.Value}
03    local char = hit.Parent
04    local hum = char:FindFirstChild("Humanoid")
05    local chance = math.random(1, #DmgValues)
06        if hum and char.Name ~= script.Parent.Parent.Name then
07        hum.Health = hum.Health - DmgValues[chance]
08        script.Disabled = true
09        wait(0.5)
10        script.Disabled = false
11 
12-- THIS PART ONLY BELOW    
13 
14        local player = game.Players.LocalPlayer
15 
View all 23 lines...

I always run into an issue here, where in the output it says, "creator is not a valid member of Humanoid"

although the explorer shows that the value is indeed inside the humanoid.

How do i make it so that the system will know that the "creator" value is there?

1 answer

Log in to vote
1
Answered by
niroqeo 123
5 years ago
Edited 5 years ago

It's because you are making the value in a localscript. Now, I am presuming you are using a localscript because it can get the player easily, but this means that no-one else will see anything the player does except for the player. The way to fix this is to turn it into a regular script and get the player by using game.Players:GetPlayerFromCharacter().

01script.Parent.Touched:Connect(function(hit)
02    local DmgValues = {script.Dmg.Value, script.DmgCritical.Value, script.Dmg2.Value, script.Dmg3.Value, script.DmgCritical2.Value}
03    local char = hit.Parent
04    local hum = char:FindFirstChild("Humanoid")
05    local chance = math.random(1, #DmgValues)
06        if hum and char.Name ~= script.Parent.Parent.Name then
07        hum.Health = hum.Health - DmgValues[chance]
08        script.Disabled = true
09        wait(0.5)
10        script.Disabled = false
11 
12        local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
13 
14        if hit.Parent.Humanoid.Health <= 0 then
15            local creator = Instance.new("ObjectValue")
View all 21 lines...
Ad

Answer this question