So I have these few combat scripts but I occasionally get problems when testing them. It is odd because I don’t get console errors and the bug doesn’t happen in studio, only when I get a friend to join the main game and actually kill each other. Resetting doesn’t cause the bug
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local tool = script.Parent
local PlayerInfo = character:FindFirstChild("PlayerInfo")
local WeaponScript
tool.Equipped:Connect(function()
print(1)
PlayerInfo = character:FindFirstChild("PlayerInfo")
print(2)
PlayerInfo.Weapon.Value = true
PlayerInfo.Weapon:FindFirstChildOfClass("ObjectValue").Name = tool.Name
print(3)
wait(1.5)
--if tool.Parent == character and character:FindFirstChild(tool.name.."Package") == nil and character.Humanoid.Health > 0 then
print(4)
print(character)
WeaponScript = game.ReplicatedStorage[tool.name.."Package"]:Clone()
print(4.5)
WeaponScript.Parent = character
--end
end)
In this script, it works perfectly as it should the first time you are in the game. If you reset your character and respawn it still works fine. If I test it in studio with 2 clients and they kill each other, it still works fine. I get a friend in the actual game, we kill each other, and it bugs out the script. There are no console errors given (so I used the prints to debug). I have come to the conclusion that ONLY SOMETIMES when a friend kills you IN GAME there is a chance for the script to end in between prints 4 and 4.5.
I kept trying ways to fix this but without a console error I’m having trouble. I don’t think it is cloning the package correctly (even though the package and character are seemingly defined correctly).
Anyone see anything wrong with this? I’ll send the script that is in the package as well just in case that may be causing problems:
local Tool = script.Parent.Parent:FindFirstChildOfClass("Tool")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local PlayerInfo = Character:FindFirstChild("PlayerInfo")
local PlayerCFrame = Character.HumanoidRootPart.CFrame
local AttackRemote = game.ReplicatedStorage.Remotes.AttackEvent
local VFXRemote = game.ReplicatedStorage.Remotes.VFXRemote
local ActionServerRemote = game.ReplicatedStorage.Remotes.ActionServerRemote
local UIS = game:GetService("UserInputService")
local Animator = Character:FindFirstChild("Humanoid").Animator
print(1)
--Information
local WeaponName = "ISOH"
UIS.InputBegan:Connect(function(input, gpe)
print(2)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if gpe then return end
if PlayerInfo.Weapon:FindFirstChildOfClass("ObjectValue").Name == WeaponName then
local data = {
["Tool"] = Tool,
["Weapon"] = WeaponName,
["Character"] = Character,
["Action"] = "M1"
}
print(2.5)
ActionServerRemote:FireServer(data)
end
end
end)
Any help would be GREATLY appreciated. I’ve been trying to fix this for hours now and I’m so lost.