I have a script which randomly drops boxes around the map. The code is thus:
local function randomBoxSpawner() local boxName = randomBoxChooser() local boxCopy = serverStorage.Boxes:FindFirstChild(boxName):Clone() local prize = boxCopy:WaitForChild("Prize").Value local debounce = true if boxCopy and prize then boxCopy.Parent = game.Workspace boxCopy.CFrame = randomLocationProvider() debris:AddItem(boxCopy, debrisWaitTime) boxCopy.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid and humanoid.Health > 0 then if debounce then local player = players:GetPlayerFromCharacter(hit.Parent) local playerInfo = serverStorage:FindFirstChild(player.Name).PlayerInfo if playerInfo.OwnsTycoon.Value then debounce = false awardBoxPrize(boxCopy, playerInfo, prize) end end end end) end end
The problem is that when I touch the box in a server it takes about one to two seconds to disappear. I thought about fading it out with a for loop but still would it not lag? What is a way that I can fix this? Quick note: I am not asking for a script, just a way to understand and fix this "problem". Thanks!
My suggestion would be as you say to fade out the box however I would suggest doing this client side so it fades out on the client side however dissapears server side. As they do not know when you touch it to open it they will not really notice the delay.