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

Script not changing Health?

Asked by
lomo0987 250 Moderation Voter
10 years ago
local Players = Game:GetService("Players")
print("STARTING")
Players.PlayerAdded:connect(function(plr) 
    local health = plr:WaitForChild("leaderstats"):WaitForChild("Health") 
    plr.CharacterAdded:connect(function(char) 
    if health.Value < 100 then
        health.Value = 100
    end
        char:WaitForChild("Humanoid").MaxHealth = health.Value 
        print("Provided health on join")
    end)
    health.Changed:connect(function(h) 
        if plr.Character then 
            plr.Character:FindFirstChild("Humanoid").MaxHealth = h 
            print("Provided health on respawn")
        end
    end)
end)

This is currently placed within the ServerScriptStorage. It's currently not doing anything. Is there anything wrong with it? (The output doesn't say anything, not even the prints.)

function DataHandler(p,o,key)   
    local types = {
        IntValue = "Number";
        NumberValue = "Number";
        ObjectValue = "Instance";
        BoolValue = "Boolean";
        StringValue="String";
    }
    local t = types[o.ClassName]
    if (not t) then return end
    key = (type(key) == "string" and key or o.Name) 
    key = (#key > 0 and key or key.Name == o.Name and o.ClassName or o.Name)
    if (not p.DataReady) then                                               
        p:WaitForDataReady()                    
    end                                         
    local Save,Load = p[("Save%s"):format(t)],p[("Load%s"):format(t)]   
    o.Value = Load(p,key)   
    local lastV = o.Value
    o.Changed:connect(function(v)
        lastV = v
        Delay(1,function()      
            if (lastV ~= v) then return end
            Save(p,key,v)
        end)
    end)
end


game.Players.PlayerAdded:connect(function(player)
    local l = Instance.new("IntValue",player)
    l.Name = "leaderstats"

    local kill = Instance.new("IntValue",l)
    kill.Name = "KOs"
    DataHandler(player,kill,"Thekills")

    local death = Instance.new("IntValue",l)
    death.Name = "Wipeouts"
    DataHandler(player,death,"Thedeaths")

    local mh = Instance.new("IntValue",l)
    mh.Name = "Health"
    DataHandler(player,mh,"MaxHealths")
end)

2 answers

Log in to vote
0
Answered by
hiccup111 231 Moderation Voter
10 years ago

This looks like something I answered earlier, did you post this again?

Anyway, plr.CharacterAdded will load too late, if it's waiting for 'health'.

Why don't you contain this with your leaderboard script, or whatever loads your leaderstats?...

e.g.

--Server-type script in ServerScriptService--

game.Players.PlayerAdded:connect(function(plr)
    Instance.new("IntValue",plr).Name = "leaderstats"
    local health = Instance.new("NumberValue",plr.leaderstats)
    health.Name = "Health"

    if health.Value < 100 then health.Value = 100 end


    plr.CharacterAdded:connect(function(char)
        char:WaitForChild("Humanoid").MaxHealth = health.Value
    end)


    health.Changed:connect(function()
        char:WaitForChild("Humanoid").MaxHealth = health.Value
    end)
end)

0
The thing is, I have a script that provides the IntValue's already. And it runs off of datasave. I want a different script to edit the IntValue's. lomo0987 250 — 10y
0
Seems a little in-efficient, and the timing may get messed up. But if you can figure a way to do it. hiccup111 231 — 10y
0
Do you just want me to upload the datasave script so you can edit it? lomo0987 250 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

ServerScriptStorage is for storing scripts. Scripts inside there will not run. ServerScriptStorage is for keeping scripts safe, for example if a game breaks, the creator has a script that extracts the script from SSS(Let's call ServerScriptStorage that for now) to fix the game. --EDIT-- I guess it isn't for that? When I put scripts in there, it never runs...

0
It's ServerScriptService, it's used to hold Server Scripts. hiccup111 231 — 10y
0
oh, sowwy :c xolbStudios 127 — 10y

Answer this question