You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
I would like to make it so that these scripts shoot one fireball regardless of the amount of players using the tool -
What is the issue?
The script shoots multiple fireballs depending on the amount of players using the same tool, for example 4 players using the tool in the server launches 4 fireballs, and this causes FPS drops. -
What solutions have you tried so far?
Did you look for solutions on the Developer Hub?
Yes, I did and they helped me find an idea on the source of the problem, but those solutions were that there were multiple scripts which caused the problem. For me, there’s supposed to be multiple scripts as the other players’ tools wouldn’t operate without them.
I tried adding a debounce timer too.
I’m looking for a solution that doesn’t require me having to create a separate remoteevent for each player, as I’d have to edit it for every other ability tool, which would be a lengthly process, if there are any.
Script:
local db = false
game.ReplicatedStorage.PipeRemotes.FireballThrow.OnServerEvent:Connect(function(player, tool)
if db == false then
local playeR = game.Players:GetPlayerFromCharacter(tool.Parent)
if player == playeR then
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
if character:FindFirstChild("Flame") then
db = true
wait(.11)
--fireball logic works fine
local function spawnFireball(positionOffset)
local fireball = game.ReplicatedStorage.FX.Fireball:Clone()
fireball.Parent = workspace.Visuals
fireball:SetPrimaryPartCFrame(humanoidRootPart.CFrame * CFrame.new(positionOffset))
local bv = Instance.new("BodyVelocity")
bv.Parent = fireball
bv.MaxForce = Vector3.one * math.huge
bv.Velocity = humanoidRootPart.CFrame.LookVector * 50
game.Debris:AddItem(fireball, 5)
end
spawnFireball(Vector3.new(0,0,-5))
wait(18.9)
db = false
end
end
end
end)
LocalScript (in the Script):
local dbounce = false
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local cooldown = 20
local tool = script.Parent.Parent.Parent
local function fireball()
if char:FindFirstChild("Flame") and dbounce == false and char:WaitForChild("RagdollTrigger").Value == false and hum.Health > 0 and not char:FindFirstChildOfClass("ForceField") then
dbounce = true
game.ReplicatedStorage.PipeRemotes.FireballThrow:FireServer(tool)
wait(cooldown)
dbounce = false
end
end
local cas = game:GetService("ContextActionService")
tool.Equipped:Connect(function()
cas:BindAction("Ability", fireball, true, Enum.KeyCode.E)
cas:SetTitle("Ability", "Fireball")
cas:SetPosition("Ability", UDim2.new(0.25, 0, 0.25, 0))
end)
tool.Unequipped:Connect(function()
cas:UnbindAction("Ability")
end)
Tell me if you need any more information or clarification.
Thanks for any help you can provide!