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)

2 comments
Keydown is deprecated do NOT use it. And wait() should NOT be your condition in while loops.
Why shouldn't wait() be your condition in while loops incapaz? I use it all the time!