Hey, I am simply not sure why it’s not working. But when testing out the game in studios everything is working fine. The combat script is there and all. But once I publish the game and load directly into the game from the game url. It’s as if the combat system doesn’t exist. I have a feel that it’s because the script is inside of the starterplayerscripts. But I still dont understand the issue.
this is the video example: Watch 2024-05-07 13-55-33 | Streamable
Here is the code for the local script in case you need it. BTW, none of the prints are working which is kinda of the indicator for me.
local UserInputService = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local Modules = RS:WaitForChild("Modules")
local WeaponsModule = require(Modules:WaitForChild("Shared"):WaitForChild("WeaponsModule"))
local player = game.Players.LocalPlayer
local animationIndex = 1
local animationCooldown = false
local BridgeNet2 = require(Modules:WaitForChild("OpenSource"):WaitForChild("BridgeNet2"))
local HitboxBridge = BridgeNet2.ClientBridge("HitboxBridge")
local lastParryTime = 0
local function playAnimation(tool, animationId, cooldown)
if player.Character:GetAttribute("IsStunned") then return end
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator") or humanoid:FindFirstChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
animationCooldown = true
wait(cooldown)
animationCooldown = false
end
local function getMaxAnimations(weaponStats)
local maxAnimations = 0
while weaponStats.animations["m" .. (maxAnimations + 1)] do
maxAnimations = maxAnimations + 1
end
return maxAnimations
end
local function handleParry()
local currentTime = tick()
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local tool = char:FindFirstChildWhichIsA("Tool")
local weaponStats = WeaponsModule.GetWeapon(tool.Name)
if currentTime - lastParryTime < weaponStats.parry.Cooldown then
print("Parry is on cooldown")
return
end
local parryAnimationId = weaponStats.animations.parry
local Animation = Instance.new("Animation")
Animation.AnimationId = weaponStats.animations.parry
local Anim = hum:LoadAnimation(Animation)
Anim.Priority = Enum.AnimationPriority.Action
Anim:Play()
local setParryingEvent = RS:WaitForChild("SetParrying")
setParryingEvent:FireServer(true)
task.wait(weaponStats.parry.Length)
setParryingEvent:FireServer(false)
lastParryTime = tick()
end
local function connectToolEvents(tool)
local weaponStats = WeaponsModule.GetWeapon(tool.Name)
local maxAnimations = getMaxAnimations(weaponStats)
local animations = weaponStats.animations
local cooldowns = weaponStats.cooldowns
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local idleAnimationID = weaponStats.animations.idle
local Animation = Instance.new("Animation")
Animation.AnimationId = idleAnimationID
local Anim = hum:LoadAnimation(Animation)
Anim.Priority = Enum.AnimationPriority.Idle
tool.Equipped:Connect(function()
Anim:Play()
print("Equipped:", tool.Name)
animationIndex = 1
local connection
connection = game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not animationCooldown and tool.Parent then
local animKey = 'm' .. animationIndex
if animations[animKey] then
HitboxBridge:Fire({tool = tool, animKey = animKey})
playAnimation(tool, animations[animKey], cooldowns[animKey])
animationIndex = (animationIndex % maxAnimations) + 1
end
end
if input.UserInputType == Enum.UserInputType.MouseButton2 and not animationCooldown and tool.Parent then
local animKey = 'criticalAttack'
if animations[animKey] then
HitboxBridge:Fire({tool = tool, animKey = animKey})
playAnimation(tool, animations[animKey], cooldowns[animKey])
end
end
if input.KeyCode == Enum.KeyCode.F and tool.Parent then
handleParry()
end
end)
tool.Unequipped:Connect(function()
connection:Disconnect()
Anim:Stop()
end)
end)
end
local function handleBackpack(backpack)
for _, item in pairs(backpack:GetChildren()) do
if item:IsA("Tool") then
connectToolEvents(item)
end
end
backpack.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
connectToolEvents(child)
end
end)
backpack.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
end
end)
end
player.CharacterAdded:Connect(function(character)
local backpack = player:WaitForChild("Backpack")
handleBackpack(backpack)
end)
local SpaceBarEvent = BridgeNet2.ClientBridge("spaceHeldEvent")
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Space then
SpaceBarEvent:Fire(true)
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(input, gameProcessed)
if not gameProcessed and input.KeyCode == Enum.KeyCode.Space then
SpaceBarEvent:Fire(false)
end
end)
local function findCharacterRootPart(name)
local dummy = game.Workspace.NPCS:FindFirstChild(name)
if dummy and dummy:FindFirstChild("HumanoidRootPart") then
return dummy.HumanoidRootPart
end
local player = game.Players:FindFirstChild(name)
if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
return player.Character.HumanoidRootPart
end
return nil
end