So i've been trying to script since last week and made a combat script "?" and i tried to find what the heck is the problem with this script for like 3 days ago... Until now I can't find out whats wrong, the output is not saying any errors. Please tell me what's wrong.
here's the localscript (Which is in StarterCharacterScripts):
local Remote = game.ReplicatedStorage.Remotes:WaitForChild("Combat")
local LP = game.Players.LocalPlayer
local Mouse = LP:GetMouse()
local CanPunch = 0
Mouse.Button1Down:Connect(function(clicked)
if CanPunch == 5 then
CanPunch = 0 return
end
if clicked and CanPunch == 0 then
wait(0.5)
CanPunch = CanPunch +1
Remote:FireServer("Punch"..CanPunch)
end
end)
And Here's the ServerScript (Which is in ServerScriptService):
local Remote = game.ReplicatedStorage.Remotes:WaitForChild("Combat")
Remote.OnServerEvent:Connect(function(player, Value)
local Char = workspace:WaitForChild(player.Name)
if Value == "Punch1" then
Char.Humanoid.Walkspeed = 5
Char.Humanoid.JumpPower = 5
local CurrentlyPunching = true
local LeftHand = Char:WaitForChild("Left Arm")
local Animation = Instance.new("Animation", Char)
Animation.AnimationId = "rbxassetid://4772213027"
Animation.Name = "Punch1"
local Animloader = Char:WaitForChild("Humanoid"):LoadAnimation(Animation)
AnimLoader:Play()
LeftHand.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Hum = hit.Parent:FindFirstChild("Humanoid")
if Hum.Parent.Name == player.Name and not hit.Parent:FindFirstChild("AlreadyHit") and CurrentlyPunching then
local F = Instance.new("IntValue", Hum.Parent)
F.Name = "AlreadyHit"
game.Debris:AddItem(F, 0.75)
Hum:TakeDamage(math.random(5, 10) + player.Data.MeleeLevel.Value)
local pnamex = Instance.new("StringValue", hit.Parent:FindFirstChild("PlayerWhoHit"))
pnamex.Name = "PlayerHitName"
pnamex.Value = player.Name
game.Debris:AddItem(pnamex, 2)
wait(1)
Hum.WalkSpeed = 16
Hum.JumpPower = 50
end
end
end)
end
if Value == "Punch2" then
Char.Humanoid.Walkspeed = 5
Char.Humanoid.JumpPower = 5
local CurrentlyPunching = true
local RightHamd = Char:WaitForChild("Right Arm")
local Animation = Instance.new("Animation", Char)
Animation.AnimationId = "rbxassetid://4772221446"
Animation.Name = "Punch2"
local Animloader = Char:WaitForChild("Humanoid"):LoadAnimation(Animation)
AnimLoader:Play()
RightHand.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Hum = hit.Parent:FindFirstChild("Humanoid")
if Hum.Parent.Name -= player.Name and not hit.Parent:FindFirstChild("AlreadyHit") and CurrentlyPunching then
local F = Instance.new("IntValue", Hum.Parent)
F.Name = "AlreadyHit"
game.Debris:AddItem(F, 0.75)
Hum:TakeDamage(math.random(5, 10) + player.Data.MeleeLevel.Value)
local pnamex = Instance.new("StringValue", hit.Parent:FindFirstChild("PlayerWhoHit"))
pnamex.Name = "PlayerHitName"
pnamex.Value = player.Name
game.Debris:AddItem(pnamex, 2)
wait(1)
Hum.WalkSpeed = 16
Hum.JumpPower = 50
end
end
end)
end
if Value == "Punch3" then
Char.Humanoid.Walkspeed = 5
Char.Humanoid.JumpPower = 5
local CurrentlyPunching = true
local RightHamd = Char:WaitForChild("Right Arm")
local LeftHamd = Char:WaitForChild("Left Arm")
local RightFoot = Char:WaitForChild("Right Leg")
local LeftFoot = Char:WaitForChild("Left Leg")
local Animation = Instance.new("Animation", Char)
Animation.AnimationId = "rbxassetid://rbxassetid://4772233148"
Animation.Name = "Punch3"
local Animloader = Char:WaitForChild("Humanoid"):LoadAnimation(Animation)
AnimLoader:Play()
RightHand.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Hum = hit.Parent:FindFirstChild("Humanoid")
if Hum.Parent.Name -= player.Name and not hit.Parent:FindFirstChild("AlreadyHit") and CurrentlyPunching then
local F = Instance.new("IntValue", Hum.Parent)
F.Name = "AlreadyHit"
game.Debris:AddItem(F, 0.75)
Hum:TakeDamage(math.random(5, 10) + player.Data.MeleeLevel.Value)
local pnamex = Instance.new("StringValue", hit.Parent:FindFirstChild("PlayerWhoHit"))
pnamex.Name = "PlayerHitName"
pnamex.Value = player.Name
game.Debris:AddItem(pnamex, 2)
wait(1)
Hum.WalkSpeed = 16
Hum.JumpPower = 50
end
end
end)
end
end)
