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

What is wrong with "onEnter(game.Players.Player)"? (Line 118)

Asked by 10 years ago
function DataHandler(p,o,key)
    delay(0,function ()
        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) -- If it's a string, keep it the same, ELSE change it to the object's name. Allows 'key' to be an optional argument.
        key = (#key > 0 and key or key.Name == o.Name and o.ClassName or o.Name)    -- If length of string is greater than 0, keep it the same
        if (not p.DataReady) then                                                       -- ELSE if it is equal to the object's name then that means that the
            p:WaitForDataReady()                                                        -- object's name is blank, therefore make 'key' the ClassName.
        end                                                                         -- ELSE make it the name of the object.
        local Save,Load = p[("Save%s"):format(t)],p[("Load%s"):format(t)]   -- Steal the load and save functions from the player
        o.Value = Load(p,key)   -- The same as p:LoadTYPE(key). Since it's no longer a method, the player must be the first argument
        local lastV = o.Value
        o.Changed:connect(function(v)
            lastV = v
            Delay(1,function()                      -- Give a 1 second buffer to see if the value changes anymore. If so, stop the operation. If it goes 1 second without changing, it will automatically save.
                if (lastV ~= v) then return end -- This way you don't save a value 20 times in 1 second if it changes constantly. Lower data processing = less lag
                Save(p,key,v)
            end)
        end)
    end)
end

function onEnter(player)
    d = Instance.new("BoolValue",player)
    d.Name = "Dead"
    d.Value = true

    a = Instance.new("BoolValue",player)
    a.Name = "Viewing"
    a.Value = true

    z = Instance.new("BoolValue",player)
    z.Name = "AllowWelcome"
    z.Value = true

    za = Instance.new("BoolValue",player)
    za.Name = "Pipebomb"
    za.Value = false
    DataHandler(player,za,"Pipebomb")

    z = Instance.new("BoolValue",player)
    z.Name = "Sniper"
    if game:GetService("BadgeService"):UserHasBadge(player.userId,78341161) then
        z.Value = true
    else
        z.Value = false
    end

    z = Instance.new("BoolValue",player)
    z.Parent = player
    z.Value = true
    z.Name = "AllowWelcome"


    i = Instance.new("IntValue",player)
    i.Parent = player
    i.Name = "leaderstats"
    i.Value = 0

    p = Instance.new("IntValue",player)
    p.Parent = i
    p.Name = ""

    o = Instance.new("StringValue",player)
    o.Parent = player
    o.Value = "Red"
    o.Name = "ChatColor"
    DataHandler(player,o,"ChatColor")

    t = Instance.new("IntValue",player)
    t.Parent = i
    t.Name = ""

    r = Instance.new("IntValue",player)
    r.Parent = i
    r.Name = ""

    deaths = Instance.new("NumberValue",player)
    deaths.Parent = player
    deaths.Name = "Deaths"
    DataHandler(player,deaths,"Deaths")

    kills = Instance.new("NumberValue",player)
    kills.Parent = player
    kills.Name = "Kills"
    DataHandler(player,kills,"kills")

    derp = Instance.new("BoolValue",player)
    derp.Parent = player
    derp.Name = "Bucket"
    DataHandler(player,derp,"Bucket")

    s = script.Spawn:Clone()
    s.name.Value = player.Name
    s.Disabled = false
    s.Parent = workspace
    s.Name = player.Name.."'s SpawnOperator"
end

function onLeave(player)
    if player == game.Workspace.PurchasedKiller.Value then
        game.Workspace.PurchasedKiller.Value = nil
        game.Workspace.EnableKillerPurchase.Value = true
    end
end

local online = game:findFirstChild("NetworkServer")
wait(1)
if not online then
    wait(2)
    onEnter(game.Players.Player)
else
    game.Players.PlayerAdded:connect(onEnter)
    game.Players.PlayerRemoving:connect(onLeave)
end

1 answer

Log in to vote
0
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

There is no child of Players named Player. If this is in offline mode, most likely the player will be named Player1.

0
So, there is no bug? iiCasual 20 — 10y
1
The bug is that game.Players.Player doesn't exist. What are you trying to do? Get the first player to join the game? Merely 2122 — 10y
1
What is the point of the if statement on line 116 anyway? What wrong with the PlayerAdded event? Perci1 4988 — 10y
0
How do I fix it ;c iiCasual 20 — 10y
Ad

Answer this question