Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A followup to my original code. Below, I have listed what to do with the following scripts:
- game > ServerScriptService > Stats
- game > StarterGui > SkillsGui > WeaponsController
- Additionally, PLEASE REMEMBER:
- MAKE A REMOTEEVENT PARENTED TO REPLICATEDSTORAGE AND NAME IT "WeaponStatsEvent"
- Below shows what to insert for game > ServerScriptService > Stats.
- local DataStoreManager = require(script:WaitForChild("DataStore"))
- local StarterData = require(script:WaitForChild("StarterData"))
- local PlayerUpdateData = require(script:WaitForChild("PlayerUpdateData"))
- local OldLoading = require(script:WaitForChild("OldLoading"))
- local DefaultData = {}
- for key, value in pairs(StarterData.StarterData) do
- DefaultData[key] = value.DefaultValue
- end
- local PlayerDataStore = DataStoreManager.new("DataStore_PlayerData", DefaultData)
- local DataHolder = Instance.new("Folder", game:GetService("ReplicatedStorage"))
- DataHolder.Name = "DataHolder"
- local PlayerData = {}
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the Stats script in a similar position.
- local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- function GetTypeFromVar(Var)
- if type(Var) == "number" then return "NumberValue"
- elseif type(Var) == "string" then return "StringValue"
- elseif type(Var) == "boolean" then return "BoolValue" end
- end
- function RegenerateData(Data, key, value)
- if key ~= nil and value ~= nil then
- local UserDataHolder = DataHolder:FindFirstChild(Data.userId)
- if UserDataHolder ~= nil then
- if UserDataHolder:FindFirstChild(key) then
- if UserDataHolder[key].ClassName == GetTypeFromVar(value) then
- UserDataHolder[key].Value = value
- else
- UserDataHolder:Destroy()
- local d = Instance.new(GetTypeFromVar(value), UserDataHolder)
- d.Name = key
- d.Value = value
- end
- else
- local d = Instance.new(GetTypeFromVar(value), UserDataHolder)
- d.Name = key
- d.Value = value
- end
- else
- RegenerateData(Data)
- end
- else
- if DataHolder:FindFirstChild(Data.userId) then DataHolder[Data.userId]:Destroy() end
- local UserDataHolder = Instance.new("Folder", DataHolder)
- UserDataHolder.Name = tostring(Data.userId)
- for k, v in pairs(Data.dataSet) do
- local d = Instance.new(GetTypeFromVar(v), UserDataHolder)
- d.Name = k
- d.Value = v
- end
- end
- end
- local Events = {}
- function PlayerAdded(Player)
- local SaveData = PlayerDataStore:GetSaveData(Player)
- for key, value in pairs(StarterData.StarterData) do
- if SaveData:Get(key) == nil or value.Permament == false then
- SaveData:Set(key, value.DefaultValue)
- end
- end
- RegenerateData(SaveData)
- Events[Player.UserId] = {}
- Events[Player.UserId]["RegenData"] = SaveData.regendata.Event:Connect(function() RegenerateData(SaveData) end)
- Events[Player.UserId]["OnUpdate"] = SaveData.onupdate.Event:Connect(function(...) RegenerateData(SaveData, ...) end)
- Player.CharacterAdded:Connect(function(Character)
- for key, value in pairs(StarterData.ResetOnSpawn) do
- SaveData:Set(key, value)
- end
- end)
- PlayerData[Player.UserId] = SaveData
- OldLoading(Player, SaveData)
- spawn(function() PlayerUpdateData(Player, SaveData) end)
- end
- function PlayerRemoving(Player)
- PlayerData[Player.UserId] = nil
- Events[Player.UserId]["RegenData"]:Disconnect()
- Events[Player.UserId]["OnUpdate"]:Disconnect()
- Events[Player.UserId] = nil
- local UserDataHolder = DataHolder:FindFirstChild(Player.UserId)
- if UserDataHolder ~= nil then
- UserDataHolder:Destroy()
- end
- end
- game:GetService("Players").PlayerAdded:Connect(PlayerAdded)
- game:GetService("Players").PlayerRemoving:Connect(PlayerRemoving)
- for _, Player in pairs(game:GetService("Players"):GetPlayers()) do PlayerAdded(Player) end
- return {
- GetStat = function(Player, ...)
- pcall(function() Player = Player.UserId end)
- if type(Player) ~= "number" then warn("You should provide id or player instance to get data!") return nil end
- local Stats = {...}
- if #Stats == 0 then warn("You should provide at least one stat!") return nil end
- if PlayerData[Player] then
- local Return = {}
- for i = 1, #Stats, 1 do
- table.insert(Return, PlayerData[Player]:Get(Stats[i]))
- end
- return unpack(Return)
- end
- return nil
- end;
- SetStat = function(Player, ...)
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the Stats script in a similar position.
- local PlayerObject = Player
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- pcall(function() Player = Player.UserId end)
- if type(Player) ~= "number" then warn("You should provide id or player instance to get data!") return nil end
- local Stats = {...}
- if #Stats == 0 or #Stats % 2 == 1 then warn("You should provide two or two's multiplier arguments!") return nil end
- if PlayerData[Player] then
- for i = 1, #Stats, 2 do
- PlayerData[Player]:Set(Stats[i], Stats[i+1])
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the Stats script in a similar position.
- if Stats[i]=="SLP" or Stats[i]=="PvP" then weaponsEvent:FireClient(PlayerObject, Stats[i], Stats[i+1]) end
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- end
- end
- return nil
- end;
- PlayerDataStore = PlayerDataStore;
- StarterData = DefaultData;
- }
- Below shows what to insert for game > StarterGui > SkillsGui > WeaponsController.
- game.ReplicatedStorage:WaitForChild("WEAPONFUNCTION")
- function CallWeaponServer(...)
- return game.ReplicatedStorage.WEAPONFUNCTION:InvokeServer(...)
- end
- game.ReplicatedStorage:WaitForChild("FUNCTION")
- function CallServer(...)
- return game.ReplicatedStorage.FUNCTION:InvokeServer(...)
- end
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the WeaponsController script in a similar position.
- local weaponsEvent = game:GetService("ReplicatedStorage"):WaitForChild("WeaponStatsEvent")
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- local DeviceType = nil
- local selectedweapon = nil
- local weapons = {}
- local gui = script.Parent
- function Weap(t, id)
- if t == "E" then
- gui.Holder["Skill"..tostring(id)].ReloadBar.Visible = true
- gui.Holder["Skill"..tostring(id)].ReloadFullBar.Visible = true
- gui.Holder["Skill"..tostring(id)].ReloadText.Visible = true
- elseif t == "UE" then
- gui.Holder["Skill"..tostring(id)].ReloadBar.Visible = false
- gui.Holder["Skill"..tostring(id)].ReloadFullBar.Visible = false
- gui.Holder["Skill"..tostring(id)].ReloadText.Visible = false
- end
- end
- function UpdateGui()
- for _, i in pairs(script.CurrentClientModules:GetChildren()) do i:Destroy() end
- for i = 1, 4 do
- if weapons[i] then
- if script.ClientModules:FindFirstChild(weapons[i]) then
- script.ClientModules[weapons[i]]:Clone().Parent = script.CurrentClientModules
- end
- end
- local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
- frame.SkillName.Text = weapons[i] or " "
- end
- end
- function UpdateGuiDevice()
- local function Check(loc)
- for _, i in pairs(loc:GetChildren()) do
- if i:IsA'Frame' then
- Check(i)
- else
- if i.Name == DeviceType.."HotKeys" then
- i.Visible = true
- elseif string.find(i.Name, "HotKeys") then
- i.Visible = false
- end
- end
- end
- end
- Check(gui.Holder)
- end
- function SkillCUC(t, i)
- if t == "C" then
- local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
- frame.SkillName.TextColor3 = Color3.new(47/255, 187/255, 200/255)
- elseif t == "UC" then
- local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
- frame.SkillName.TextColor3 = Color3.new(1,1,1)
- end
- end
- function SetupGui()
- script.Parent.Holder.Visible = true
- for i = 1, 4 do
- local frame = gui.Holder:FindFirstChild("Skill"..tostring(i))
- frame.SkillName.Text = weapons[i] or " "
- frame.SkillName.MouseButton1Click:connect(function()
- if weapons[i] ~= nil then
- SelectWeapon(i)
- end
- end)
- end
- end
- local debounce = {[1] = true, [2] = true, [3] = true, [4] = true}
- local debounceuse = true
- local LastUse = tick()
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the WeaponsController script in a similar position.
- local SLPvalue = 0
- local PvPvalue = 0
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- function Use()
- local curweaponf = selectedweapon
- if debounceuse then
- debounceuse = false
- if debounce[curweaponf] then
- -- These are the old lines. Delete these.
- --if CallServer("GetStat", "PvP") == 1 then
- --if CallServer("GetStat", "SLP") == 0 and CallServer("GetHumanoidHealth") ~= 0 then
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the WeaponsController script in a similar position.
- if PvPvalue == 1 then
- if SLPvalue == 0 and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character.Humanoid.Health > 0 then
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- if script.CurrentClientModules:FindFirstChild(weapons[curweaponf]) then
- game.Players.LocalPlayer.PlayerGui.GameGui.LocalScript.WeaponUsed.Value = true
- debounce[curweaponf] = false
- local tab = require(script.CurrentClientModules[weapons[curweaponf]])
- local func = tab[1]
- local reload = tab[2]
- spawn(function() local returned = func(game.Players.LocalPlayer, DeviceType, CallServer, CallWeaponServer) if returned ~= nil then reload = returned end LastUse = tick() end)
- spawn(function()
- local i = 0
- while i < reload do
- if 0.8 * (i / (reload)) < 0.1 then
- gui.Holder["Skill"..tostring(curweaponf)].ReloadBar:TweenSize(UDim2.new(0.1, 0, -0.15, 0), "Out", "Quad", 1, true)
- else
- gui.Holder["Skill"..tostring(curweaponf)].ReloadBar:TweenSize(UDim2.new(0.8 * (i / (reload)), 0, -0.15, 0), "Out", "Quad", 1, true)
- end
- gui.Holder["Skill"..tostring(curweaponf)].ReloadText.Text = "Reloading!"
- i = i + wait(1/60)
- end
- gui.Holder["Skill"..tostring(curweaponf)].ReloadBar:TweenSize(UDim2.new(0.8, 0, -0.15, 0), "Out", "Quad", 1, true)
- gui.Holder["Skill"..tostring(curweaponf)].ReloadText.Text = "Ready!"
- debounce[curweaponf] = true
- end)
- SkillCUC("UC", curweaponf)
- selectedweapon = nil
- end
- end
- else
- game.StarterGui:SetCore("SendNotification", {
- Title = "Skills";
- Text = "Turned the PvP on!";
- Duration = 2;
- })
- CallServer("ChangeStat", "PvP", 1)
- end
- end
- wait(2)
- debounceuse = true
- end
- end
- function SelectWeapon(num)
- if weapons[num] ~= nil then
- if selectedweapon == num then
- selectedweapon = nil
- SkillCUC("UC", num)
- else
- selectedweapon = num
- SkillCUC("C", num)
- if num ~= 1 then SkillCUC("UC", 1) end
- if num ~= 2 then SkillCUC("UC", 2) end
- if num ~= 3 then SkillCUC("UC", 3) end
- if num ~= 4 then SkillCUC("UC", 4) end
- end
- end
- end
- game.Players.LocalPlayer.Backpack.ChildAdded:connect(function(i)
- if script.ClientModules:FindFirstChild(i.Name) then
- script.ClientModules[i.Name]:Clone().Parent = script.CurrentClientModules
- end
- if weapons[1] == nil then table.insert(weapons, 1, i.Name) Weap("E", 1)
- elseif weapons[2] == nil then table.insert(weapons, 2, i.Name) Weap("E", 2)
- elseif weapons[3] == nil then table.insert(weapons, 3, i.Name) Weap("E", 3)
- elseif weapons[4] == nil then table.insert(weapons, 4, i.Name) Weap("E", 4)
- end
- UpdateGui()
- end)
- game.Players.LocalPlayer.Backpack.ChildRemoved:connect(function(i)
- if script.CurrentClientModules:FindFirstChild(i.Name) then
- script.CurrentClientModules[i.Name]:Destroy()
- end
- if weapons[1] == i.Name then weapons[1] = nil Weap("UE", 1) if selectedweapon == 1 then selectedweapon = nil SkillCUC("UC", 1) end
- elseif weapons[2] == i.Name then weapons[2] = nil Weap("UE", 2) if selectedweapon == 2 then selectedweapon = nil SkillCUC("UC", 2) end
- elseif weapons[3] == i.Name then weapons[3] = nil Weap("UE", 3) if selectedweapon == 3 then selectedweapon = nil SkillCUC("UC", 3) end
- elseif weapons[4] == i.Name then weapons[4] = nil Weap("UE", 4) if selectedweapon == 4 then selectedweapon = nil SkillCUC("UC", 4) end
- end
- UpdateGui()
- end)
- repeat wait() until weapons[1] ~= nil
- SetupGui()
- local debounce = true
- game:GetService("UserInputService").InputBegan:connect(function(input, gp)
- if debounce then
- debounce = false
- if input.UserInputType == Enum.UserInputType.Gamepad1 or input.UserInputType == Enum.UserInputType.Keyboard then
- -- EXECUTING
- if input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.ButtonL1 then
- if weapons[1] ~= nil then
- SelectWeapon(1)
- end
- elseif input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.ButtonL2 then
- if weapons[2] ~= nil then
- SelectWeapon(2)
- end
- elseif input.KeyCode == Enum.KeyCode.R or input.KeyCode == Enum.KeyCode.ButtonR2 then
- if weapons[3] ~= nil then
- SelectWeapon(3)
- end
- elseif input.KeyCode == Enum.KeyCode.T or input.KeyCode == Enum.KeyCode.ButtonR1 then
- if weapons[4] ~= nil then
- SelectWeapon(4)
- end
- elseif input.KeyCode == Enum.KeyCode.ButtonX then
- if selectedweapon ~= nil then
- Use()
- end
- end
- elseif input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- if not gp then
- if selectedweapon ~= nil then
- Use()
- end
- end
- end
- debounce = true
- end
- end)
- local UIS = game:GetService("UserInputService")
- if UIS.GamepadEnabled then
- DeviceType = "Gamepad"
- UpdateGuiDevice()
- elseif UIS.MouseEnabled then
- DeviceType = "Pc"
- UpdateGuiDevice()
- elseif UIS.TouchEnabled then
- DeviceType = "Mobile"
- UpdateGuiDevice()
- end
- UIS.GamepadConnected:connect(function(GPN)
- if GPN == Enum.UserInputType.Gamepad1 then
- DeviceType = "Gamepad"
- UpdateGuiDevice()
- end
- end)
- UIS.GamepadDisconnected:connect(function(GPN)
- if GPN == Enum.UserInputType.Gamepad1 then
- if UIS.MouseEnabled then
- DeviceType = "Pc"
- UpdateGuiDevice()
- elseif UIS.TouchEnabled then
- DeviceType = "Mobile"
- UpdateGuiDevice()
- end
- end
- end)
- spawn(function()
- local CurHP = CallServer("GetHP")
- local LastHPChange = tick()
- while wait(1) do
- local HP = CallServer("GetHP")
- if HP < CurHP then LastHPChange = tick() end
- CurHP = HP
- if tick() - LastUse > 6 and tick() - LastHPChange > 6 then
- CallServer("HealPlayer", 10)
- LastUse = tick()
- end
- end
- end)
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- NEW STUFF
- -- Copy the below line and paste it into the WeaponsController script in a similar position.
- weaponsEvent.OnClientEvent:Connect(function(...)
- local args = {...}
- --[1]: the name of a stat
- --[2]: the stat's new value
- if args[1]=="SLP" then
- SLPvalue = args[2]
- elseif args[1]=="PvP" then
- PvPvalue = args[2]
- end
- end)
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- -- END OF NEW STUFF
- goo luck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement