tech/game

21/07/29 Shop Menu 추가

tech-lover 2021. 7. 29. 13:28

https://tech5g.tistory.com/299 이전 글 참고

 

- gui localscript

```

local open = game.Workspace.openShop

local close = game.Workspace.closeShop

local frame = script.Parent

local closeButton = frame.closeButton

local apply1 = frame.apply1

local apply2 = frame.apply2

local apply3 = frame.apply3



local ReplacatedStorage = game:GetService('ReplicatedStorage')

local remoteEvent = ReplacatedStorage:WaitForChild('ApplyTool')

 

frame.Visible = false

 

local function shopMenu(hit)

    local player = game.Players:FindFirstChild(hit.Parent.Name)

    

    if player and player.PlayerGui.ScreenGui.Shop.Visible == false then

        --print(player)

        player.PlayerGui.ScreenGui.Shop.Visible = true

        player.Character.Humanoid.WalkSpeed = 0

 

    end 

end

 

local function closeMenu()

    local player = game.Players.LocalPlayer

    

    if player and player.PlayerGui.ScreenGui.Shop.Visible == true then

        --print(player)

        player.PlayerGui.ScreenGui.Shop.Visible = false

        -- player.Character.HumanoidRootPart.Orientation = close.Orientation

        player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X, close.Position.Y+3, close.Position.Z)

        player.Character.Humanoid.WalkSpeed = 16

    end 

end

 

local function applyTool1()

    

    local tool = ReplacatedStorage.ShopItems.TommyGun  

    remoteEvent:FireServer(tool)

    

end



local function applyTool2()

 

    local tool = ReplacatedStorage.ShopItems.ClassicSword

    remoteEvent:FireServer(tool)

 

end

 

local function applyTool3()

 

    local tool = ReplacatedStorage.ShopItems.HyperGun

    remoteEvent:FireServer(tool)

 

end



open.Touched:Connect(shopMenu)

closeButton.MouseButton1Click:Connect(closeMenu)

apply1.MouseButton1Click:Connect(applyTool1)

apply2.MouseButton1Click:Connect(applyTool2)

apply3.MouseButton1Click:Connect(applyTool3)

```

 

-- ServerSideScript/ApplyTool

```

local ReplacatedStorage = game:GetService('ReplicatedStorage')

local remoteEvent = ReplacatedStorage:WaitForChild('ApplyTool')

 

local function applyTool(playertool)

    -- print(player.Name)

    -- print(tool.Name)

    

    if player.leaderstats.Money.Value >= tool.Price.Value then

        

        player.leaderstats.Money.Value = player.leaderstats.Money.Value - tool.Price.Value

        

    

        -- TODOS (backpack, StarterGear isn't working 21/07/29)

        --[[

        local giveTool = ReplacatedStorage.ShopItems[tool.Name]:Clone()

        giveTool.Parent = player.BackPack

        

        local giveTool = ReplacatedStorage.ShopItems[tool.Name]:Clone()

        giveTool.Parent = player.StarterGear

        ]]

            

    end

end

 

remoteEvent.OnServerEvent:connect(applyTool)

```

 

-- TODO

 

leaderstats 화면 표시하기