So I’ve discovered a bug with my game that if left unfixed would make my game practically unplayable.
I have a simple fireball tool that will fire a remote event to a server script inside starter character scripts to launch a fireball. It works perfectly, however if you use it enough the fireball will start to not launch at all and keep you permastunned. Here are my scripts:
Server side (StarterCharacterScripts):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local SkillEvent = ReplicatedStorage.FireSkillUsed
local SkillEndedEvent = ReplicatedStorage.FireSkillEnded
local assets = ReplicatedStorage.Assets.Fire
local MouseRequest = ReplicatedStorage:WaitForChild("MouseRequest")
local MouseReply = ReplicatedStorage:WaitForChild("MouseReply")
local Players = game:GetService("Players")
local myCharacter = script.Parent
local myPlayer = Players:GetPlayerFromCharacter(myCharacter)
local Humanoid = myCharacter.Humanoid
local SecureData = require(ServerScriptService:WaitForChild("SecureData"))
local Stun = require(ReplicatedStorage:WaitForChild("StunManager"))
local AnimID1 = "rbxassetid://132127577863396"
local Move1CD = 3
local Move1OnCd = false
local AnimID2 = "rbxassetid://132127577863396"
local Move2CD = 3
local Move2OnCd = false
local AnimID3 = "rbxassetid://132127577863396"
local Move3CD = 3
local Move3OnCd = false
local AnimID4 = "rbxassetid://132127577863396"
local Move4CD = 3
local Move4OnCd = false
SkillEvent.OnServerEvent:Connect(function(Player, SkillName)
if Player ~= myPlayer then
return
end
if Move1OnCd == false then
Move1OnCd = true
task.delay(Move1CD - 0.01, function()
Move1OnCd = false
end)
local Values = Player.Character:FindFirstChild("Values")
if Values.Stunned.Value == false then
if Values.MoveStunned.Value == false then
Stun.StartMoveStun(Player.Character)
if SkillName == "Fireball" then
local VFX = assets.FireballModel.Explosion
local Projectile = assets.FireballModel
local anim = Instance.new("Animation")
anim.AnimationId = AnimID1
local track = Humanoid:LoadAnimation(anim)
track:Play()
Humanoid.WalkSpeed = 5
local ProjectileClone = Projectile:Clone()
local stats = SecureData[Player.UserId]
if stats then
if stats.Level <= 999 then
stats.XP = (stats.XP or 0) + 150
else
end
end
local Hitbox = ProjectileClone.Hitbox
Hitbox.Sender.Value = Player.Name
Hitbox.Damage.Value = 10 + ((SecureData[Player.UserId].Level) * 0.1)
task.wait(1.4)
ProjectileClone.Parent = workspace.VFX
ProjectileClone.CFrame = myCharacter["Right Arm"].CFrame
Hitbox.Parent = ReplicatedStorage
MouseRequest:FireClient(myPlayer)
MouseReply.OnServerEvent:Once(function(returningPlayer, mousePosition)
if returningPlayer ~= myPlayer then
return
end
local origin = myCharacter["Right Arm"].Position
local direction = (mousePosition - origin).Unit * 100
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {
game.Workspace.TestPart,
ProjectileClone,
myCharacter["Right Arm"],
myCharacter["Left Arm"],
myCharacter["Right Leg"],
myCharacter["Left Leg"],
myCharacter.Head,
myCharacter.HumanoidRootPart
}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
local hitPos = raycastResult and raycastResult.Position or (origin + direction)
local distance = (hitPos - origin).Magnitude
local speed = 100
local duration = distance / speed
local tween = game:GetService("TweenService"):Create(
ProjectileClone,
TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
{Position = hitPos}
)
tween:Play()
tween.Completed:Once(function()
ProjectileClone.FireballVFX.BallTrail.Enabled = false
ProjectileClone.FireballVFX.Embers.Enabled = false
ProjectileClone.FireballVFX.Main.Enabled = false
ProjectileClone.Explosion:Emit()
Hitbox.Parent = workspace.Hitboxes
Hitbox.Position = ProjectileClone.Position
task.delay(0.1, function()
Hitbox.Position = Vector3.new(-999999999, 999999999, 999999999)
end)
game.Debris:AddItem(Hitbox, 5)
end)
SkillEndedEvent:FireClient(Player, SkillName)
Player:SetAttribute("IFrames", false)
Stun.EndMoveStun(Player.Character)
Humanoid.WalkSpeed = 16
end)
else
warn("Skill "..SkillName.." is invalid.")
end
end
end
end
end)
Client side (Fireball tool):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SkillEvent = ReplicatedStorage.FireSkillUsed
local Skill = script.Parent
local players = game:GetService("Players")
local Player = players.LocalPlayer
local Character = Player.Character
local Root = Character.HumanoidRootPart
local SkillEndedEvent = ReplicatedStorage.FireSkillEnded
local CD = 3
local OnCD = false
local Mouse = Player:GetMouse()
local RunService = game:GetService("RunService")
local UsingMove = false
Skill.Activated:Connect(function()
if OnCD == false then
if Character:WaitForChild("Values").Stunned.Value == false then
if Character:WaitForChild("Values").MoveStunned.Value == false then
Character.Humanoid.AutoRotate = false
OnCD = true
SkillEvent:FireServer(Skill.Name)
UsingMove = true
wait(CD)
OnCD = false
end
end
end
end)
RunService.RenderStepped:Connect(function()
if UsingMove == true then
local MousePos = Mouse.Hit.Position
local RootPos, MousePos = Root.Position, Mouse.Hit.Position
Root.CFrame = CFrame.new(RootPos, Vector3.new(MousePos.X, RootPos.Y, MousePos.Z))
end
end)
SkillEndedEvent.OnClientEvent:Connect(function(SkillName)
if SkillName == Skill.Name then
UsingMove = false
Character.Humanoid.AutoRotate = true
end
end)
It seems that every time i throw one there’s a small chance for this to happen. Any and all help is appreciated. Thank you!