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

Waitforchild not working?

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
game.Players.PlayerAdded:connect(function(p)
    local leaderstat = Instance.new("Model")
    leaderstat.Name = "leaderstat"
    leaderstat.Parent = p
        local c = Instance.new("StringValue")
    c.Name = "coords"
    c.Value = 2
    c.Parent = leaderstat
end)


game.Players.PlayerAdded:connect(function(p)
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = p
    local hunger = Instance.new("NumberValue")
    hunger.Name = "Hunger"
    hunger.Value = 100
    hunger.Parent = leaderstats
    local thirst = Instance.new("NumberValue")
    thirst.Name = "thirst"
    thirst.Value = 100
    thirst.Parent = leaderstats
end)


print("here here")
player = game.Players.LocalPlayer
print("code blue")
local e = false

if player.Hunger.Value <= 10 then
    e = true
    while e do
        wait(2)
    player.Character.Humanoid.Health = player.Character.Humanoid.Health - 10
    end
end


if player.Character.Humanoid.Health <= 0 then
    e = false
end

basically, this is for a hunger stat. it does the leaderstats part perfectly, but it doesnt print code blue. it doees print here here, which is why i know the waitforchild is messing up. am i using it wrong? or is it something else?

0
is this a local scirpt? koolkid8099 705 — 8y
0
no, why would it be. theCJarmy7 1293 — 8y
0
IF you using LocalPlayer, then the script has to be a local script or else it won't work koolkid8099 705 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You do not need to use :WaitForChild() on line 13. Also LocalPlayer wouldn't be a "Child" of player, more like an Instance of it. Player is the first thing made when a player enters the game. So therefore, that is not needed. You can simply define player as

game.Players.LocalPlayer
0
Workspace.stats:32: attempt to index local 'player' (a nil value) which is what happens when i define player as game.players.localplayer. i know its reffering to the localplayer part, because when i take out the variable part, in the output it says Workspace.stats:31: attempt to index field 'LocalPlayer' (a nil value) theCJarmy7 1293 — 8y
Ad

Answer this question