im making a combat script, and im trying to script the damage part in a server script (so the target just doesnt die on the client) and for some reason it doesnt work. There are no errors in the output
Heres the code
Code (Client)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not DBounce then --Another way of saying "mouse.Button1Down"
DBounce = true
if random:NextInteger(1,2) == 1 then
punch1Track:Play()
humanoid.WalkSpeed = 0
LArm.Touched:Connect(function(hit)
if not DBounce2 then
DBounce2 = true
REvent:FireServer()--Event that fires to the damage script in Server
wait(waitTime)
print("e")
DBounce2 = false
end
end)
```
Code (Server)
local REvent = game.ReplicatedStorage:WaitForChild("CombatEvent")
REvent.OnServerEvent:Connect(function(player)
print(player.Name)
local character = player.Character or player.CharacterAdded:Wait()
local LArm = character:WaitForChild("Left Arm")
print("event reached server")
LArm.Touched:Connect(function(hit)
print(hit)
end)
end)
The output isn’t printing what i’d like it to print. Help would be appreciated, thank you for your time
local RS = game:GetService("ReplicatedStorage")
local REvent = RS:WaitForChild("CombatEvent")
REvent.OnServerEvent:Connect(function(player)
local character = player.Character
local LArm = character:WaitForChild("Left Arm")
LArm.Touched:Connect(function(hit)
print(hit.Name)
end)
end)
There’s the server script. Remember that only R6 avatars have “Left Arm” as a valid member of their character model.
if input.UserInputType == Enum.UserInputType.MouseButton1 and not DBounce then --Another way of saying "mouse.Button1Down"
DBounce = true
if random:NextInteger(1,2) == 1 then
punch1Track:Play()
humanoid.WalkSpeed = 0
LArm.Touched:Connect(function(hit)
if not DBounce2 then
DBounce2 = true
REvent:FireServer()--Event that fires to the damage script in Server
wait(waitTime)
print("e")
DBounce2 = false
end
end)
```
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local LeftArm = Character:WaitForChild("Left Arm")
local PunchAnim = script:WaitForChild("Animation") --change this to name of animation inside script (change the reference if animation isnt in script)
local PunchTrack = Humanoid:LoadAnimation(PunchAnim)
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local REvent = RS:WaitForChild("CombatEvent")
local DBounce = false
local DBounce2 = false
local random = Random.new()
UIS.InputBegan:Connect(function(input, processed)
if processed then
return
end
if DBounce then
return
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
DBounce = true
if random:NextInteger(1, 2) == 1 then
PunchTrack:Play()
Humanoid.WalkSpeed = 0
LeftArm.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Char = hit.Parent
if Char ~= Character then
REvent:FireServer()
end
end
end)
end
task.wait(3) --cooldown length
DBounce = false
end
end)
That isn’t the full script but I tried to fill in the blanks.