Firstly, I want to know if it is possible to even pass variables through remote functions. I am trying to do a complete combat, and I am having trouble detecting combos on server script when I have it on local script. Basiclly depending on the combo, I want it to do more damage.
Local script:
local ServerEvent = game.ReplicatedStorage:WaitForChild("ServerEvent")
local UserInputService = game:GetService("UserInputService")
local tool = script.Parent
local idleAnim = tool:WaitForChild("CombatIdle")
local blockAnim = tool:WaitForChild("Block")
local combo1 = tool:WaitForChild("Combo1")
local combo2 = tool:WaitForChild("Combo2")
local combo3 = tool:WaitForChild("Combo3")
local equipped = false
local canAttack = true
local combo = 0
local timeUntilComboResets = 1.5
local lastTimeClicked = tick()
BlockKey = Enum.KeyCode.R
tool.Equipped:Connect(function()
equipped = true
character = tool.Parent
isPlayerBlocking = character:FindFirstChild("isPlayerBlocking")
humanoid = character:FindFirstChild("Humanoid")
end)
tool.Activated:Connect(function()
if equipped and isPlayerBlocking.Value == false and canAttack == true then
if tick() - lastTimeClicked >= timeUntilComboResets then
combo = 0
end
lastTimeClicked = tick()
combo = combo + 1
print(combo)
if combo == 1 then
combo1Track = humanoid:LoadAnimation(combo1)
combo1Track:Play()
ServerEvent:FireServer(combo)
canAttack = false
wait(0.3)
canAttack = true
elseif combo == 2 then
combo2Track = humanoid:LoadAnimation(combo2)
combo2Track:Play()
ServerEvent:FireServer(combo)
canAttack = false
wait(0.3)
canAttack = true
elseif combo == 3 then
combo1Track:Play()
ServerEvent:FireServer(combo)
canAttack = false
wait(0.3)
canAttack = true
elseif combo >= 4 then
combo3Track = humanoid:LoadAnimation(combo3)
combo3Track:Play()
ServerEvent:FireServer(combo)
combo = 0
canAttack = false
wait(0.3)
canAttack = true
end
end
end)
tool.Unequipped:Connect(function()
combo = 0
equipped = false
character = nil
isPlayerBlocking = nil
humanoid = nil
end)
UserInputService.InputBegan:Connect(function(InputObject,gameProcessed)
if InputObject.KeyCode == BlockKey and isPlayerBlocking.Value == false and equipped == true then
isPlayerBlocking.Value = true
print("BLOCKING")
BlockTrack = humanoid:LoadAnimation(blockAnim)
BlockTrack:Play()
BlockTrack.Looped = true
end
end)
UserInputService.InputEnded:Connect(function(InputObject,gameProcessed)
if InputObject.KeyCode == BlockKey and isPlayerBlocking.Value == true and equipped == true then
isPlayerBlocking.Value = false
print("BLOCK ENDED!")
BlockTrack:Stop()
BlockTrack.Looped = false
end
end)
Server script:
local ServerEvent = game.ReplicatedStorage:WaitForChild("ServerEvent")
local tool = script.Parent
local hitAnim = tool:WaitForChild("GettingHit")
local equipped = false
tool.Equipped:Connect(function()
Ourcharacter = tool.Parent
equipped = true
end)
local humanoidsHit = {}
local damage = 5
local hitWalkSpeed = 2
ServerEvent.OnServerEvent:Connect(function(combo)
for i,v in pairs(game.Workspace:GetChildren("Model")) do
if v:IsA("Model") then
if v.Humanoid and v.HumanoidRootPart then
if v ~= Ourcharacter then
local otherRootPart = v.HumanoidRootPart
local ourRootPart = Ourcharacter.HumanoidRootPart
local magnitude = (ourRootPart.Position - otherRootPart.Position).Magnitude
local unit = (ourRootPart.Position - otherRootPart.Position).Unit
local dot = unit:Dot(Ourcharacter.Head.CFrame.LookVector)
if magnitude <= 2 and dot <= 0.5 then
local descandants = v:GetDescendants()
for i, descandant in pairs(descandants) do
if descandant:IsA("BoolValue") then
local isPlayerBlocking = descandant
if isPlayerBlocking.Name == "isPlayerBlocking" then
if isPlayerBlocking.Value == true then
print("OTHER PLAYER IS BLOCKING")
else
print("PLAYER IS NOT BLOCKING")
if combo >= 4 then
print("Combo 4")
end
local hitTrack = `
v.Humanoid:LoadAnimation(hitAnim)
hitTrack:Play()
v.Humanoid.WalkSpeed = 2
end
end
end
end
end
end
end
end
end
end)