Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Infinite yield possible on 'ReplicatedStorage:WaitForChild("BuyTool")' how can i do?

Asked by 2 years ago
local open = game.Workspace.openPart

local close = game.Workspace.closePart

local frame = script.Parent

local closeButton = frame.closeButton

local buy_1 = frame.buy1

local buy_2 = frame.buy2

local buy_3 = frame.buy3



local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')



frame.Visible = false



local function shopMenu(otherPart)

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

    if player then

        player.Character.Humanoid.WalkSpeed = 0

    end

end



local function closeMenu()

    local player = game.Players.LocalPlayer

    player.PlayerGui.ScreenGui.Shop.Visible = false

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

    player.Character.Humanoid.WalkSpeed = 16

end



local function buyTool1()

    local tool = ReplicatedStorage.ShopItems['Name of Tool1']

    remoteEvent:FireServer(tool)

end



local function buyTool2()

    local tool = ReplicatedStorage.ShopItems['Name of Tool2']

    remoteEvent:FireServer(tool)

end



local function buyTool3()

    local tool = ReplicatedStorage.ShopItems['Name of Tool3']

    remoteEvent:FireServer(tool)

end



open.Touched:Connect(shopMenu)

closeButton.MouseButton1Click:Connect(closeMenu)

buy_1.MouseButton1Click:Connect(buyTool1)

buy_2.MouseButton1Click:Connect(buyTool2)

buy_3.MouseButton1Click:Connect(buyTool3)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Try this:

local open = game.Workspace.openPart

local close = game.Workspace.closePart

local frame = script.Parent

local closeButton = frame.closeButton

local buy_1 = frame.buy1

local buy_2 = frame.buy2

local buy_3 = frame.buy3



local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage.BuyTool



frame.Visible = false



local function shopMenu(otherPart)

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

    if player then

        player.Character.Humanoid.WalkSpeed = 0

    end

end



local function closeMenu()

    local player = game.Players.LocalPlayer

    player.PlayerGui.ScreenGui.Shop.Visible = false

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

    player.Character.Humanoid.WalkSpeed = 16

end



local function buyTool1()

    local tool = ReplicatedStorage.ShopItems['Name of Tool1']

    remoteEvent:FireServer(tool)

end



local function buyTool2()

    local tool = ReplicatedStorage.ShopItems['Name of Tool2']

    remoteEvent:FireServer(tool)

end



local function buyTool3()

    local tool = ReplicatedStorage.ShopItems['Name of Tool3']

    remoteEvent:FireServer(tool)

end



open.Touched:Connect(shopMenu)

closeButton.MouseButton1Click:Connect(closeMenu)

buy_1.MouseButton1Click:Connect(buyTool1)

buy_2.MouseButton1Click:Connect(buyTool2)

buy_3.MouseButton1Click:Connect(buyTool3)
Ad

Answer this question