Just need help with a little something regarding my script, so basically im trying to make a fighting game(with the help of AI because I have absolutely zero knowledge in coding), and after finishing the script, I realize this is just a local script when I play tested, so I just wanted help on turning all the animations, damage, etc into actually things that can be seen by actual players. Here is my script, all help is appreciated.
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local UserInputService = game:GetService(“UserInputService”)
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild(“Humanoid”)
local Animator = Humanoid:WaitForChild(“Animator”)
local CombatData = require(ReplicatedStorage:WaitForChild(“CombatData”))
local animations = {}
local currentCombo = 0
local isAnimationPlaying = false
local lastAttackTime = 0
local cooldownTime = 1.5 – Cooldown time in seconds after the fourth attack
local comboResetTime = 1.3 – Time in seconds to reset combo if no input
local isInCooldown = false
local isStunned = false
local originalWalkSpeed = Humanoid.WalkSpeed
– Load animations
local function loadAnimations(animator)
for name, id in pairs(CombatData.Animations) do
local anim = Instance.new(“Animation”)
anim.AnimationId = “rbxassetid://” … id
animations[name] = animator:LoadAnimation(anim)
print(“Loaded animation:”, name, “with ID:”, id)
end
end
loadAnimations(Animator)
local function setWalkSpeed(speed)
Humanoid.WalkSpeed = speed
end
local function resetCombo()
currentCombo = 0
print(“Combo reset”)
setWalkSpeed(originalWalkSpeed) – Reset walk speed to original
end
local function startCooldown()
isInCooldown = true
print(“Cooldown started”)
task.delay(cooldownTime, function()
isInCooldown = false
print(“Cooldown ended”)
setWalkSpeed(originalWalkSpeed) – Reset walk speed to original after cooldown
end)
end
local function stunPlayer()
isStunned = true
setWalkSpeed(0) – Set walk speed to 0 to prevent movement
print(“Player stunned for 1 second”)
task.delay(1, function()
isStunned = false
setWalkSpeed(originalWalkSpeed)
print(“Stun ended”)
end)
end
local function performAttack()
local currentTime = tick()
-- Check if we're in cooldown or stunned
if isInCooldown or isStunned then
print("Cannot attack: " .. (isInCooldown and "In cooldown" or "Stunned"))
return
end
-- Check if it's time to reset the combo
if currentTime - lastAttackTime > comboResetTime then
resetCombo() -- Reset combo if no input for specified time
end
if isAnimationPlaying then
print("Animation is still playing, cannot start a new one")
return
end
currentCombo = (currentCombo % #CombatData.ComboOrder) + 1
local attackName = CombatData.ComboOrder[currentCombo]
print("Attempting to play animation:", attackName, "Combo:", currentCombo)
local animation = animations[attackName]
if animation then
isAnimationPlaying = true
setWalkSpeed(8) -- Set walk speed to 8 when combo starts
animation:Play()
print("Playing animation:", attackName)
animation.Stopped:Connect(function()
print("Animation finished:", attackName)
isAnimationPlaying = false
if currentCombo == 4 then
stunPlayer() -- Call stunPlayer after the fourth attack
startCooldown() -- Start cooldown after the fourth attack
else
task.wait(0.1) -- Small delay between animations
end
end)
else
print("Animation not found:", attackName)
end
lastAttackTime = currentTime
-- Reset the combo timer only after a successful attack
task.delay(comboResetTime, function()
if tick() - lastAttackTime >= comboResetTime then
resetCombo()
end
end)
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input.UserInputType == Enum.UserInputType.MouseButton1 then
print(“Mouse clicked, calling performAttack()”)
performAttack() – Perform the attack
end
end)