Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dss = game:GetService("DataStoreService")
- local ds = dss:GetDataStore("DATA")
- local trails = game.ReplicatedStorage:WaitForChild("Trails")
- function createAtchs(char)
- local hrp = char:WaitForChild("HumanoidRootPart")
- local atchTop = Instance.new("Attachment", hrp)
- atchTop.Name = "TrailTop"
- atchTop.Position = Vector3.new(0, 0.766, 0)
- local atchBtm = Instance.new("Attachment", hrp)
- atchBtm.Name = "TrailBottom"
- atchBtm.Position = Vector3.new(0, -0.766, 0)
- end
- function saveData(plrLeaving)
- local ownedTrails = {}
- for i, trail in pairs(plrLeaving.OwnedTrails:GetChildren()) do
- table.insert(ownedTrails, trail.Name)
- end
- local success, err = pcall(function()
- ds:SetAsync("trails-" .. plrLeaving.UserId, ownedTrails)
- ds:SetAsync("money-" .. plrLeaving.UserId, plrLeaving.leaderstats.Money.Value)
- end)
- end
- game.Players.PlayerAdded:Connect(function(plr)
- local trailsOwned = {}
- local money = 2000
- pcall(function()
- trailsOwned = ds:GetAsync("trails-" .. plr.UserId) or {}
- money = ds:GetAsync("money-" .. plr.UserId) or 2000
- end)
- local ls = Instance.new("Folder", plr)
- ls.Name = "leaderstats"
- local moneyValue = Instance.new("IntValue", ls)
- moneyValue.Name = "Money"
- moneyValue.Value = money
- local ownedFolder = Instance.new("Folder", plr)
- ownedFolder.Name = "OwnedTrails"
- for i, owned in pairs(trailsOwned) do
- if trails:FindFirstChild(owned) then
- trails[owned]:Clone().Parent = ownedFolder
- end
- end
- if plr.Character then createAtchs(plr.Character) end
- plr.CharacterAdded:Connect(createAtchs)
- end)
- game.Players.PlayerRemoving:Connect(saveData)
- game:BindToClose(function()
- for i, plrLeaving in pairs(game.Players:GetPlayers()) do
- saveData(plrLeaving)
- end
- end)
- game.ReplicatedStorage.TrailSelectedRE.OnServerEvent:Connect(function(plr, buying, trail)
- if buying and not plr.OwnedTrails:FindFirstChild(trail.Name) then
- local price = trail.Price.Value
- local money = plr.leaderstats.Money
- if price <= money.Value then
- money.Value -= price
- trail:Clone().Parent = plr.OwnedTrails
- end
- elseif not buying and plr.OwnedTrails:FindFirstChild(trail.Name) then
- local char = plr.Character
- if not char or not char:FindFirstChild("HumanoidRootPart") then return end
- for i, child in pairs(char.HumanoidRootPart:GetChildren()) do
- if child:IsA("Trail") then child:Destroy() end
- end
- local newTrail = trail:Clone()
- newTrail.Attachment0 = char.HumanoidRootPart.TrailTop
- newTrail.Attachment1 = char.HumanoidRootPart.TrailBottom
- newTrail.Parent = char.HumanoidRootPart
- end
- end)
Add Comment
Please, Sign In to add comment