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

Need help with this script on picking up "Item"?? The game freezes?

Asked by 5 years ago

Alright so I have this script, but when I try to test in studio, the game freezes and this call stack bar shows up. It points to this script, it also asks me to break or kill the script. I don't know what is wrong please help lol.

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local key = "f"
local sound = game.Workspace:WaitForChild("pickup")
local playerGui = plr:WaitForChild("PlayerGui")
local inventory = playerGui:WaitForChild("Inventory")
local InvService = require(inventory.InventoryService)
local PickupImage = "http://www.roblox.com/asset/?id=1476363789"

spawn(function()
    while wait() do
        if mouse.Target then
            if mouse.Target:FindFirstChild("item") then
                mouse.Icon = PickupImage
            else
                mouse.Icon = ""
            end
        else
            mouse.Icon = ""
        end
    end
end)

mouse.KeyDown:connect(function(k)
    if k:lower() == key then
        if mouse.Target then
            if mouse.Target:FindFirstChild("item") then
                local result = InvService.addOneItem(mouse.Target.Name)
                if result then
                    sound:Play()
                    game.ReplicatedStorage.Events.dest:FireServer(mouse.Target)
                end
            end
        end
    end
end)

0
Keydown is deprecated do NOT use it. And wait() should NOT be your condition in while loops. User#19524 175 — 5y
0
Why shouldn't wait() be your condition in while loops incapaz? I use it all the time! Zenith_Lord 93 — 5y

Answer this question