Advertisement
HowToRoblox

CharacterShopHandler

May 22nd, 2021
3,699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. local re = game.ReplicatedStorage:WaitForChild("CharacterRE")
  2. local chars = game.ReplicatedStorage:WaitForChild("Characters")
  3.  
  4.  
  5. local shop = script.Parent:WaitForChild("Shop")
  6. local inv = script.Parent:WaitForChild("Inventory")
  7.  
  8.  
  9. script.Parent.OpenShop.MouseButton1Click:Connect(function()
  10.     shop.Visible = not shop.Visible
  11. end)
  12.  
  13. script.Parent.OpenInventory.MouseButton1Click:Connect(function()
  14.     inv.Visible = not inv.Visible
  15. end)
  16.  
  17.  
  18. shop.CharacterPreview.BuyButton.MouseButton1Click:Connect(function()
  19.    
  20.     re:FireServer(true, shop.CharacterPreview.CharacterName.Text)
  21. end)
  22.  
  23.  
  24.  
  25. for i, char in pairs(chars:GetChildren()) do
  26.    
  27.     local price = char.Price.Value
  28.     local displayChar = char:Clone()
  29.    
  30.    
  31.     local button = script.SelectButton:Clone()
  32.     button.Name = char.Name
  33.    
  34.     local cam = Instance.new("Camera", button.CharacterViewer)
  35.     button.CharacterViewer.CurrentCamera = cam
  36.    
  37.     displayChar.Parent = button.CharacterViewer
  38.    
  39.     cam.CFrame = CFrame.new(displayChar.HumanoidRootPart.Position + Vector3.new(0, -0.5, 5), displayChar.HumanoidRootPart.Position)
  40.    
  41.     button.Parent = shop.CharacterSelector
  42.    
  43.    
  44.     button.MouseButton1Click:Connect(function()
  45.  
  46.         shop.CharacterPreview.CharacterName.Text = char.Name
  47.         shop.CharacterPreview.BuyButton.Text = "BUY for " .. price
  48.  
  49.         shop.CharacterPreview.CharacterViewer:ClearAllChildren()
  50.  
  51.         local viewerCam = Instance.new("Camera", shop.CharacterPreview.CharacterViewer)
  52.         shop.CharacterPreview.CharacterViewer.CurrentCamera = viewerCam
  53.  
  54.         displayChar:Clone().Parent = shop.CharacterPreview.CharacterViewer
  55.  
  56.         viewerCam.CFrame = CFrame.new(displayChar.HumanoidRootPart.Position + Vector3.new(0, -0.5, 5), displayChar.HumanoidRootPart.Position)
  57.     end)
  58. end
  59.  
  60.  
  61. game.Players.LocalPlayer.OwnedCharacters.ChildAdded:Connect(function(child)
  62.  
  63.    
  64.     local button = shop.CharacterSelector[child.Name]:Clone()
  65.     button.Parent = inv.CharacterSelector
  66.  
  67.     button.MouseButton1Click:Connect(function()
  68.  
  69.         re:FireServer(false, child.Name)
  70.     end)
  71. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement