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

My script seems to not be running at all?

Asked by 3 years ago

hello guys

basically this is my server script which is in serverscriptservice

it wont run at all..it wont even print anything right after i put a print statement in the player added function at the start.. i get no errors in the output

i will give you the other scripts so you dont get errors about not having them etc.

script that wont run anything

local Key = 25
local DataStoreService = game:GetService("DataStoreService")
local PlayerData = DataStoreService:GetDataStore("PlayerData"..Key)
local LeaderboardData = DataStoreService:GetOrderedDataStore("LeaderboardData"..Key)

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local PhysicsService = game:GetService("PhysicsService"); PhysicsService:CreateCollisionGroup("PlayersCollision"); PhysicsService:CollisionGroupSetCollidable("PlayersCollision", "PlayersCollision", false)
local RNG = Random.new()    

local Modules = ServerStorage:WaitForChild("Modules")
local Data = require(Modules:WaitForChild("Data"))
local TreeHandler = require(Modules:WaitForChild("Tree Handler"))

local ReplicatedModules = ReplicatedStorage:WaitForChild("Modules")
local Information = require(Modules:WaitForChild("Information"))

local Map = workspace:WaitForChild("Map")
local Zones = Map:WaitForChild("Zones")

local Cutters = ServerStorage:WaitForChild("Cutters")
local Bags = ServerStorage:WaitForChild("Bags")
local Pets = ServerStorage:WaitForChild("Pets")

local Events = ReplicatedStorage:WaitForChild("Events")
local Chop = Events:WaitForChild("Dig")
local Buy = Events:WaitForChild("Buy")
local Sell = Events:WaitForChild("Sell")    
local Equip = Events:WaitForChild("Equip")
local UpdateInventory = Events:WaitForChild("UpdateInventory")
local EmptyBag = Events:WaitForChild("EmptyBag")
local GetInventory = Events:WaitForChild("GetInventory")
local GetZones = Events:WaitForChild("GetZones")
local BuyZone = Events:WaitForChild("BuyZone")
local HideEmptyBagGUI = Events:WaitForChild("HideEmptyBagGUI")

local SessionData = {}

Players.PlayerAdded:Connect(function(Player)

    print("yes")

    Player.CharacterAdded:Connect(function(Character)
        repeat wait() until SessionData[Player.UserId]
        local data = SessionData[Player.UserId]
        Equip(Player,data.Owned.Cutters[data.Equipped.Cutter])
        Equip(Player,data.Owned.Bags[data.Equipped.Bag])
        UpdateBag(Player, data)

        for i, v in pairs(Character:GetDescendants()) do
            if v:IsA("BasePart") then
                PhysicsService:SetPartCollisionGroup(v, "PlayersCollision")
            end
        end

        if HasGamepass(Player, "VIP") then
            -- vip head gui
        end

    end)

    Data.Load(Player, PlayerData, SessionData)

    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"

    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Value = SessionData[Player.UserId].Coins  
    Coins.Parent = Leaderstats

    Leaderstats.Parent = Player

    if HasGamepass(Player, "Infinite Storage") then
        SessionData[Player.UserId].Max = math.huge
    end


end)

Players.PlayerRemoving:Connect(function(Player)
    Data.Save(Player, PlayerData, SessionData[Player.UserId])
end)

game:BindToClose(function()
    for _, Player in pairs(game.Players:GetPlayers()) do
        spawn(function() Data.Save(Player, PlayerData, SessionData[Player.UserId]) end)
    end
end)

local MarketplaceService = game:GetService("MarketplaceService")

function ProcessDevProduct(Info)
    local Player = Players:GetPlayerByUserId(Info.UserId)

    if not Player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if Info.ProductId == 1082033158 then -- 10K 
        SessionData[Player.UserId].Coins = SessionData[Player.UserId].Coins + 10000
        Player.leaderstats.Coins.Value = SessionData[Player.UserId].Coins
    end

    if Info.ProductId == 1082033198 then -- 20K 
        SessionData[Player.UserId].Coins = SessionData[Player.UserId].Coins + 20000
        Player.leaderstats.Coins.Value = SessionData[Player.UserId].Coins
    end

    if Info.ProductId == 1082033234 then -- 50K 
        SessionData[Player.UserId].Coins = SessionData[Player.UserId].Coins + 50000
        Player.leaderstats.Coins.Value = SessionData[Player.UserId].Coins
    end

    if Info.ProductId == 1082033290 then -- 100K 
        SessionData[Player.UserId].Coins = SessionData[Player.UserId].Coins + 100000
        Player.leaderstats.Coins.Value = SessionData[Player.UserId].Coins
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted

end

MarketplaceService.ProcessReceipt = ProcessDevProduct

function ProcessGamepass(Player, ID, PurchaseSuccess)
    if not PurchaseSuccess then return end

    if ID == 11364534 then
        SessionData[Player.UserId].Coins = SessionData[Player.UserId].Coins + 7500
        Player.leaderstats.Coins.Value = SessionData[Player.UserId].Coins
    end

    if ID == 11364529 then
        SessionData[Player.UserId].Max = math.huge
        UpdateBag(Player, SessionData[Player.UserId])
    end

    if ID == 11364526 then
        HideEmptyBagGUI:FireClient(Player)
        --SellInventory(Player)
    end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(ProcessGamepass)

function EquipItem(Player, Item)
    if not Item then return end
    local Type = IsA(Item)
    if Type == "Cutters" then
        Player.Backpack:ClearAllChildren()
        if Player.Character:FindFirstChild("Cutter") then Player.Character.Cutter:Destroy() end
        local Cutter = Cutters[Item]:Clone()
        Cutter.Name = "Cutter"
        Cutter.Parent = Player.Backpack
    end
    if Type == "Bags" then
        if Player.Character:FindFirstChild("Bag") then Player.Character.Bag:Destroy() end
        local Bag = Bags[Item]:Clone()
        Bag.Name = "Bag"
        local Motor6D = Instance.new("Motor6D")
        Motor6D.Part0 = Bag
        Motor6D.Part1 = Player.Character.UpperTorso
        Motor6D.C0 = Information.Bags[Item].Position
        Motor6D.Parent = Bag
        Bag.Parent = Player.Character
    end
end

Equip.OnServerEvent:Connect(function(Player, Item, Position)

    local Equipped = SessionData[Player.UserId].Equipped
    local Type = IsA(Item)
    local Position = Position

    if not Position then

        for i, v in pairs(SessionData[Player.UserId].Owned[Type]) do

            if Item == v then
                Position = i
            end

        end

    end

    local Category = string.sub(Type, 1,(string.len(Type)-1))

    SessionData[Player.UserId].Equipped[Category] = Position

    if Type == "Bags" then
        if HasGamepass(Player, "Infinite Storage") then
            SessionData[Player.UserId].Max = math.huge else
            SessionData[Player.UserId].Max = Information[Type][Item].Power
        end
    end

    EquipItem(Player, Item)
    UpdateBag(Player, SessionData[Player.UserId])

end)

function IsA(Item)
    if Information.Cutters[Item] then
        return "Cutters" else if Information.Bags[Item] then
            return "Bags" else if Information.Pets[Item] then
                return "Pets" else
                return "Trails"
            end
        end
    end
end

function UpdateBag(Player, Inventory)
    Player.Character.Bag.Storage.TextLabel.Text = Inventory.Storage.."/"..Inventory.Max
end

function HasGamepass(Player, Gamepass)
    return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Information.Gamepasses[Gamepass])
end

data module

local Data = {}

function Data.Load(Player, DataStore, SessionData)
    local Success, PlayerData = pcall(function()
        return DataStore:GetAsync(Player.UserId)
    end)

    if Success then
        if not PlayerData then
            print(" Default Data Loaded")
            PlayerData = {
                LastChop = tick(),
                Coins = 0,
                Storage = 0,
                Max = 10,
                WoodChopped = 0,
                FirstJoined = tick(),
                Zones = {
                    ["Zone 1"] = false,
                    [" Zone 2"] = false,
                    ["Zone 3"] = false,
                    ["Zone 4"] = false,
                },
                Equipped  = {
                    Shovel = 1,
                    Bag = 1,
                    Pet = nil,
                    Trail = nil,
                },
                Owned = {
                    Cutters = {"Axe"},
                    Bags = {"Starter Bag"},
                    Pets = {},
                    Trails = {},
                },

                Temporary = false
            }
        end else
        print("Temporary Data Loaded")
        PlayerData = {
                LastChop = tick(),
                Coins = 0,
                Storage = 0,
                Max = 10,
                WoodChopped = 0,
                FirstJoined = tick(),
                Zones = {
                    ["Zone 1"] = false,
                    [" Zone 2"] = false,
                    ["Zone 3"] = false,
                    ["Zone 4"] = false,
                },
                Equipped  = {
                    Shovel = 1,
                    Bag = 1,
                    Pet = nil,
                    Trail = nil,
                },
                Owned = {
                    Cutters = {"Axe"},
                    Bags = {"Starter Bag"},
                    Pets = {},
                    Trails = {},
                },

                Temporary = false
        }
        PlayerData.Temporary = true
    end

    SessionData[Player.UserId] = PlayerData
end

function Data.Save(Player, DataStore, PlayerData)
    if PlayerData.Temporary == true then return end

    local Success, Error = pcall(function()
        DataStore:SetAsync(Player.UserId, PlayerData)
        print(Player.Name.." data has been saved!")
        PlayerData = nil
    end)

    if not Success then
        print("Saving failed!")
    end

end


return Data

information module

local Information = {}

Information.Zones = {
    ["Zone 1"] = 5000,
    ["Zone 2"] = 15000,
    ["Zone 3"] = 30000,
    ["Zone 4"] = 60000,
}

Information.Gamepasses {
    ["Double Coins"] = 11364523,
    ["Auto Sell"] = 11364526,
    ["Infinite Storage"] = 11364529,
    ["VIP"] = 11364534,
}

Information.Cutters = {
    ["Axe"] = {
        ID = "rbxassetid://5595260519",
        Name = "Axe",
        Power = 1,
        Price = 0,
    }
}

Information.Bags = {
    ["Starter Bag"] = {
        ID = "rbxassetid://5595347345",
        Name = "Starter Bag",
        Power = 10,
        Price = 0,
        Position = CFrame.new(0,-.2,1.05) * CFrame.Angles(math.rad(10),math.rad(180),0)
    }
}

Information.Pets {
    --pets
}

Information.Trails = {
    --trails
}

return Information

thanks guys

0
does the problem script print yes from line 43? AlexTheCreator 461 — 3y
0
Nope CoreMcNugget 15 — 3y
0
surely when you have so many waitforchilds theres a problem right? have you tried putting playeradded at the top? zadobyte 692 — 3y
0
i kept the player added in the same spot and pretty much commented out every wait for child possible which was the majority. it wont work at the spot the player added is in, but it works at the top of the script for some reason.. CoreMcNugget 15 — 3y
View all comments (4 more)
0
Go steal a different script zane21225 243 — 3y
0
@skvyy ? I am using the original as a template to help me learn scripting..? I didn’t realize that this was possibly stolen? I’m only using it for learning CoreMcNugget 15 — 3y
0
LOOOOOOOOOOOOOOOOOOOOOL, I suggest learning to program rather than taking scripts and hoping for them to work. 220+ lines of code is too much, on top of that another 2 scripts is far too much greatneil80 2647 — 3y
0
Sorry buddy but I actually am learning... I know how 95% of this script works. I have learned all the basics concepts and I am learning the more advanced concepts. ScriptingHelpers is for people to get help, not be disrespected because they are using a script that they changed to learn. Yes I used a pre made script but I didn’t know it was stolen. I changed parts of it and this has helped me learn CoreMcNugget 15 — 3y

1 answer

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago

in your Information Module your missing a couple of equals when defining your tables.

Information.Gamepasses { .... }
--// Should be 
Information.Gamepasses = { .... }

and

Information.Pets { ... }
--// should be
Information.Pets = { ... }

I've not included the actual data so its easyer to read. From what you've given us the rest of the code "should" work unless theres another error on another module/script someplace.

All i can say man thats a lot of waitforchild calls i would put a time out on those... Im thinking your script might be still waiting for something to load, might be your information module. Since it's got errors it just simply stops your main script.

Example on how to put a time out:

local parent:Waitforchild(thingyouwanttoload,30) --// wait 30 seconds

Url on the wiki about WaitForChild() function: https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

Hope this helps! :)

Ad

Answer this question