i dont know why sometimes it can not be collected, maybe there are too many people in the same server or the script is overloading or what ? Is there anyways that I can fix it ?
here is the gems script (located in ServerScriptService) it handle all the Gems
-- Alternative implementation
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFolder = ReplicatedStorage:WaitForChild("GemsGuiRemote")
local GemsValue = 1
--
local debounceGems = {} -- Dictionary of gem-objects that are currently in 'debounce'
--
local function GemHideThenReappear(gem)
--gem.Position = Vector3.new(-195.806, 1.322, -189.686)
wait(5)
-- Reappear
--local pos1 = math.random(1340.551, 1409.617)
--local pos2 = math.random(501.232, 501.232)
--local pos3 = math.random(81.194, 117.067)
--gem.Position = Vector3.new(pos1,pos2,pos3)
gem.Sparkles.Enabled = true
local tween = TweenService:Create(gem, TweenInfo.new(0.5), { Transparency = 0 } )
-- Once tween has completed, then un-debounce the object
tween.Completed:Connect(function()
debounceGems[gem] = nil
end)
tween:Play()
end
--
local function GemTouched(gem, hit)
if not debounceGems[gem] then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player ~= nil then
RemoteFolder.ShowGems:FireClient(player,GemsValue)
-- Set debounce for only this particular object
debounceGems[gem] = true
local PlayerBackpackCapacity = hit.Parent:FindFirstChild("Backpack").capacity
if player.leaderstats.Gems.Value + GemsValue >= PlayerBackpackCapacity.Value then
player.TotalGems.Value = player.TotalGems.Value + (PlayerBackpackCapacity.Value - player.leaderstats.Gems.Value)
else
player.TotalGems.Value = player.TotalGems.Value + GemsValue
end
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + GemsValue
gem.GemsSound:Play()
gem.Sparkles.Enabled = false
local tween = TweenService:Create(gem, TweenInfo.new(0.5), { Transparency = 1 } )
-- Once tween has completed, then hide the object
tween.Completed:Connect(function()
GemHideThenReappear(gem)
end)
tween:Play()
end
end
end
--
for _,gem in ipairs(CollectionService:GetTagged("MainIslandGems")) do
gem.Touched:Connect(function(hit)
-- Need to supply the `GemTouched`-function with what `gem`-object that is actually being touched
GemTouched(gem, hit)
end)
end