My punching script does not work after the player dies or resets. It uses region3. I send the player’s position but it does not update on the server.
Local Script:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local Enabled = true
local RE = script:WaitForChild("Function")
player.CharacterAdded:Connect(function (char)
hrp = char:WaitForChild("HumanoidRootPart")
print(hrp)
end)
UIS.InputBegan:Connect(function (input, GPE)
if GPE then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if Enabled == true then
RE:FireServer("Combat", hrp.CFrame * CFrame.new(0,0, -2.5).Position, char)
print(hrp.CFrame * CFrame.new(0,0, -2.5).Position)
Enabled = false
wait(0.4)
Enabled = true
end
end
end)
Server Script:
local RE = script.Parent
local Enabled = true
local combo = 1
RE.OnServerEvent:Connect(function(player, action, Pos)
local char = player.Character or player.CharacterAdded:Wait()
print(Pos)
if Enabled == false then return end
Enabled = false
if action == "Combat" then
if combo == 1 then
combo = 2
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://7008354558"
local Anim = char.Humanoid:LoadAnimation(Track)
Anim:Play()
local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
for i, v in pairs(playingTracks) do
if v.Name == "walk" or v.Name == "run" then
v:Destroy()
end
end
elseif combo == 2 then
combo = 1
local Track = Instance.new("Animation")
Track.AnimationId = "rbxassetid://7008358588"
local Anim = char.Humanoid:LoadAnimation(Track)
Anim:Play()
local playingTracks = char.Humanoid.Animator:GetPlayingAnimationTracks()
for i, v in pairs(playingTracks) do
if v.Name == "walk" or v.Name == "run" then
v:Destroy()
end
end
end
if char.Humanoid:FindFirstChild("Whoosh") then
local whoosh = char.Humanoid:WaitForChild("Whoosh")
whoosh:Play()
else
local sound = Instance.new("Sound", char.Humanoid)
sound.Name = "Whoosh"
sound.SoundId = "rbxassetid://231731980"
sound.PlaybackSpeed = math.random(88, 120)/100
sound:Play()
end
print("REGION")
local HRP = char:WaitForChild("HumanoidRootPart")
local RegionPart = game.ServerStorage.RegionPart:Clone()
print("Cloned")
RegionPart.Parent = workspace
RegionPart.Position = Pos
game.Debris:AddItem(RegionPart, 0.5)
local region = Region3.new(Pos - (RegionPart.Size/2), Pos + (RegionPart.Size/2))
local RTable = workspace:FindPartsInRegion3(region, RegionPart, 30)
print(RTable)
for i, v in pairs(RTable) do
if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Deb") == nil and v.Parent ~= char and v.Parent:FindFirstChild("Humanoid").Health ~= 0 then
local Deb = Instance.new("BoolValue", v.Parent)
Deb.Name = "Deb"
game.Debris:AddItem(Deb, 0.4)
local randomDMG = math.random(15,20)
v.Parent.Humanoid:TakeDamage(randomDMG)
print(randomDMG)
if v:FindFirstChild("Punch") then
local punch = v:WaitForChild("Punch")
punch:Play()
else
local s = Instance.new("Sound", v)
s.Name = "Punch"
s.SoundId = "rbxassetid://3932505023"
s.PlaybackSpeed = math.random(88, 120)/100
s:Play()
end
local attachment1 = Instance.new("Attachment", v.Parent:FindFirstChild("HumanoidRootPart"))
local fx = game.ServerStorage:WaitForChild("FX")
local punchFX = fx:WaitForChild("PUNCH")
local random = math.random(0, 2)
--if random == 1 then
-- local particle = punchFX.Effects2:Clone()
-- particle.Parent = attachment1
-- particle:Emit(10)
-- wait(0.2)
-- particle:Destroy()
-- print("ELLLO")
--elseif random == 2 then
local particle = punchFX.HitModuleParticle:Clone()
particle.Parent = attachment1
particle:Emit(10)
wait(0.2)
particle:Destroy()
print("ELLO 2")
--end
if v.Parent.Humanoid.Health <= 25 then
local Push = Instance.new("BodyVelocity", v.Parent:FindFirstChild("HumanoidRootPart"))
Push.MaxForce = Vector3.new(1,0,1) * 20000
Push.Velocity = char.HumanoidRootPart.CFrame.lookVector * 50
game.Debris:AddItem(Push, 0.3)
end
end
end
Enabled = true
end
end)
Please help. This is driving me insane.
Here’s a video of the incident: