Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keyModule = require(script.Parent:WaitForChild("Game Logic").KeyModule)
- local roundModule = require(script.Parent:WaitForChild("Game Logic").RoundModule)
- local DataStoreService = game:GetService("DataStoreService")
- local DataStore = DataStoreService:GetDataStore("MyDataStore2")
- game.Players.PlayerAdded:Connect(function(player)
- -- Insert a value tag inside the player so we can tell whether they are in the menu or not. This way we can tell which players are
- -- active and ready to play, and prevents AFK players from joining a round when it starts, as they are still in the Menu GUI.
- local inMenu = Instance.new("BoolValue")
- inMenu.Name = "InMenu"
- inMenu.Parent = player
- -- AddToTutorial
- local piggyTokens = Instance.new("IntValue")
- piggyTokens.Name = "Tokens"
- piggyTokens.Value = 1000
- piggyTokens.Parent = player
- local trapInventory = Instance.new("Folder")
- trapInventory.Name = "TrapInventory"
- trapInventory.Parent = player
- local skinInventory = Instance.new("Folder")
- skinInventory.Name = "SkinInventory"
- skinInventory.Parent = player
- local equippedTrap = Instance.new("StringValue")
- equippedTrap.Name = "EquippedTrap"
- equippedTrap.Parent = player
- local equippedSkin = Instance.new("StringValue")
- equippedSkin.Name = "EquippedSkin"
- equippedSkin.Parent = player
- local data = DataStore:GetAsync(player.UserId)
- if data ~= nil then
- if data.EquippedTrap then
- equippedTrap.Value = data.EquippedTrap
- print("loaded equipped trap : "..tostring(data.EquippedTrap))
- end
- if data.EquippedSkin then
- equippedSkin.Value = data.EquippedSkin
- print("loaded equipped skin : "..tostring(data.EquippedSkin))
- end
- if data.Tokens then
- piggyTokens.Value = data.Tokens
- print(data.Tokens.." tokens loaded")
- end
- if data.Skins then
- print("bring it")
- for i, v in pairs(data.Skins) do
- local val = Instance.new("StringValue")
- val.Name = v
- val.Parent = skinInventory
- end
- end
- if data.Traps then
- print("bring it")
- for i, v in pairs(data.Traps) do
- local val = Instance.new("StringValue")
- val.Name = v
- val.Parent = trapInventory
- end
- end
- end
- game.ReplicatedStorage.SendData:FireClient(player,data)
- player.CharacterAdded:Connect(function(char)
- char.Humanoid.Died:Connect(function()
- if char:FindFirstChild("HumanoidRootPart") then
- if player:FindFirstChild("Contestant") and game.Workspace:FindFirstChild("Map") then -- added
- keyModule.DropTools(player,game.Workspace.Map,char.HumanoidRootPart.Position)
- end
- end
- if player:FindFirstChild("Contestant") then
- player.Contestant:Destroy()
- elseif player:FindFirstChild("Piggy") then
- player.Piggy:Destroy()
- end
- end)
- end)
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local data = {}
- data.Tokens = player.Tokens.Value
- data.EquippedTrap = player.EquippedTrap.Value
- data.EquippedSkin = player.EquippedSkin.Value
- data.Skins = {}
- data.Traps = {}
- for i, v in pairs(player.SkinInventory:GetChildren()) do
- table.insert(data.Skins,v.Name)
- print(v.Name)
- end
- for i, v in pairs(player.TrapInventory:GetChildren()) do
- table.insert(data.Traps,v.Name)
- print(v.Name)
- end
- DataStore:SetAsync(player.UserId,data)
- print("saved")
- end)
- game:BindToClose(function()
- for i, player in pairs(game.Players:GetPlayers()) do
- local data = {}
- data.Tokens = player.Tokens.Value
- data.EquippedTrap = player.EquippedTrap.Value
- data.EquippedSkin = player.EquippedSkin.Value
- data.Skins = {}
- data.Traps = {}
- for i, v in pairs(player.SkinInventory:GetChildren()) do
- table.insert(data.Skins,v.Name)
- print(v.Name)
- end
- for i, v in pairs(player.TrapInventory:GetChildren()) do
- table.insert(data.Traps,v.Name)
- print(v.Name)
- end
- DataStore:SetAsync(player.UserId,data)
- print("saved")
- end
- end)
- local trapDebounce = false
- game.ReplicatedStorage.PlaceTrap.OnServerEvent:Connect(function(player)
- if player:FindFirstChild("Piggy") then
- if player:FindFirstChild("TrapCount") then
- if not trapDebounce then
- trapDebounce = true
- if player.TrapCount.Value > 0 then
- if game.Workspace:FindFirstChild("Map") then
- player.TrapCount.Value = player.TrapCount.Value - 1
- local trap
- if player.EquippedTrap.Value ~= "" then
- if game.ReplicatedStorage.Traps:FindFirstChild(player.EquippedTrap.Value) then
- trap = game.ReplicatedStorage.Traps[player.EquippedTrap.Value]:Clone()
- end
- else
- trap = game.ReplicatedStorage.Traps.Bear_Trap:Clone()
- end
- trap.CFrame = player.Character.HumanoidRootPart.CFrame - Vector3.new(0,3.5,0)
- trap.Parent = game.Workspace:FindFirstChild("Map")
- end
- end
- wait(5)
- trapDebounce = false
- end
- end
- end
- end)
- game.ReplicatedStorage.MenuPlay.OnServerEvent:Connect(function(player)
- print("test")
- if player:FindFirstChild("InMenu") then
- -- Remove the InMenu tag so that you can be counted as an active player.
- player.InMenu:Destroy()
- end
- if game.ServerStorage.GameValues.GameInProgress.Value == true then
- local contestant = Instance.new("BoolValue")
- contestant.Name = "Contestant"
- contestant.Parent = player
- game.ReplicatedStorage.ToggleCrouch:FireClient(player,true)
- roundModule.TeleportPlayers({player},game.Workspace:FindFirstChild("Map").PlayerSpawns:GetChildren())
- end
- end)
- game.ReplicatedStorage.BuyTrap.OnServerInvoke = function(player,trapName)
- local trap = game.ReplicatedStorage.Traps:FindFirstChild(trapName)
- if trap then
- if trap:FindFirstChild("Cost") then
- if not player.TrapInventory:FindFirstChild(trapName) then
- if trap.Cost.Value <= player.Tokens.Value then
- print("You can buy this")
- player.Tokens.Value = player.Tokens.Value - trap.Cost.Value
- local stringValue = Instance.new("StringValue")
- stringValue.Name = trap.Name
- stringValue.Parent = player.TrapInventory
- return "bought"
- else
- print("Not enough money")
- return "failed"
- end
- else
- print("You already own this item - equipping")
- player.EquippedTrap.Value = trapName
- return "equipped"
- end
- end
- else
- print("No Trap of such Name found")
- return "failed"
- end
- end
- game.ReplicatedStorage.BuySkin.OnServerInvoke = function(player,skinName)
- local skin = game.ReplicatedStorage.Skins:FindFirstChild(skinName)
- if skin then
- if skin:FindFirstChild("Cost") then
- if not player.SkinInventory:FindFirstChild(skinName) then
- if skin.Cost.Value <= player.Tokens.Value then
- print("You can buy this")
- player.Tokens.Value = player.Tokens.Value - skin.Cost.Value
- local stringValue = Instance.new("StringValue")
- stringValue.Name = skin.Name
- stringValue.Parent = player.SkinInventory
- return "bought"
- else
- print("Not enough money")
- return "failed"
- end
- else
- print("You already own this item - equipping")
- player.EquippedSkin.Value = skinName
- return "equipped"
- end
- end
- else
- print("No Skin of such Name found")
- return "failed"
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement