Hello All! I’ve began working on a custom backpack for use in a game, however I’ve run into an issue with one specific tool.
The tool just stops working, when It’s moved into the character through my custom backpack system. All other tools that I’ve made work fine but the “Detonator” tool just doesn’t seem to want to work when it’s enabled through my custom backpack.
I am getting a “Remote event invocation queue exhausted” error, which I assume is due to passing the mouses position through a remote event every frame. However I don’t get this error when the tool is in the starterpack.
Local Script
local mouse = game.Players.LocalPlayer:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
script.Parent.ThrowDetonator:FireServer(mouse.Hit)
end)
Server Script
local tool = script.Parent
local char
tool.Equipped:Connect(function()
char = tool.Parent
end)
tool.Unequipped:Connect(function()
char = nil
end)
local mouseCF
tool.ThrowDetonator.OnServerEvent:Connect(function(plr, mouseHit)
mouseCF = mouseHit
end)
tool.Activated:Connect(function()
char.Humanoid:LoadAnimation(script.Animation):Play()
wait(0.1)
local clone = tool.Handle:Clone()
local bv = Instance.new("BodyVelocity")
bv.Velocity = mouseCF.LookVector * 100
bv.Parent = clone
clone.Parent = workspace
clone.CanCollide = true
clone.Thrown:Play()
local explodeCoro = coroutine.wrap(function()
tool:Destroy()
wait(1)
clone.Beeping:Play()
clone.PointLight.Enabled = true
wait(.5)
clone.PointLight.Enabled = false
wait(.5)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.25)
clone.PointLight.Enabled = false
wait(0.25)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.25)
clone.PointLight.Enabled = false
wait(0.25)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.25)
clone.PointLight.Enabled = false
wait(0.25)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.25)
clone.PointLight.Enabled = false
wait(0.25)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = false
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = false
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = false
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = true
clone.Beeping:Play()
wait(0.110)
clone.PointLight.Enabled = false
clone.Beeping:Play()
wait(0.110)
local maxDmg = 130 --Maximum Damage change this for balancing purposes
local minDmg = 10 --Minimum Damage change this for balancing purposes
local explosion = Instance.new("Explosion")
explosion.Position = clone.Position
explosion.Parent = clone
explosion.ExplosionType = "NoCraters"
explosion.BlastRadius = 30 --Radius in which players will take damage
explosion.BlastPressure = 40 --Pressure
explosion.DestroyJointRadiusPercent = 0
clone.Explosion:Play()
clone.PointLight.Color = Color3.fromRGB(255,80,0)
clone.PointLight.Enabled = true
clone.PointLight.Range = 10
clone.Transparency = 1
explosion.Hit:Connect(function(hit,distance)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
print(player.Name.." Was hit by an explosion.")
if hum then
local damaged = player.isDamaged.Damaged
if damaged.Value == false then
damaged.Value = true
print("damaged the player")
hum:TakeDamage((1 - distance / explosion.BlastRadius) * (maxDmg - minDmg) + minDmg)
wait(1) --Change this to reduce or increase time before players can be hurt by another detonator
end
wait(0.5) --Changes this to reduce or increase the time before players can be hurt by another detonator
damaged.Value = false
end
end
end)
wait(0.5)
clone.PointLight.Enabled = false
wait(2.76)
clone:Destroy()
end)
explodeCoro()
wait(0.1)
bv:Destroy()
wait(4 - 0.2)
end)
Sorry If it’s something simple in my script that I’m just overlooking.
Further Info
The backpack system I’ve made is a GUI which we clone Icons into. Each icon has an equip button. The equip button access a folder under the player which I called “Inventory” which just contains all the tools which can be easily cloned in through replicated storage. The equip button then clones the desired tool into the character so It can be accessed like a normal tool.
Thanks in advance!