this is a combat script it works when a player first joins but the next time they die or if a new player joins after players have joined the script fails work again

Local Script:


local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")

local ready = true

local function punch(inputObject, gameProcessed)
	if inputObject.KeyCode == Enum.KeyCode.E and ready then
		punchEvent:FireServer()
		ready = false
		wait(0.5)
		ready = true
	end
end

UserInputService.InputBegan:Connect(punch)
-----------------

ServerScript

math.randomseed(tick())

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
punchEvent.Name = "PunchEvent"

local animations = {3584762599, 3584757508, 3584743590} 

local function onPunchFired(plr)
	local char = game.Workspace:FindFirstChild(plr.Name)
	local humanoid = char.Humanoid
	local animation = Instance.new("Animation")
	local picked = math.random(1, #animations)
	animation.AnimationId = "http://roblox.com/asset/?id="..animations[picked]
	local animTrack = humanoid:LoadAnimation(animation)
	animTrack:Play()
	local dmgScript = script.DmgScript:Clone()
	if picked == 1 then
		dmgScript.Parent = char["Left Arm"]
	elseif picked == 2 then
		dmgScript.Parent = char["Right Arm"]
		elseif picked == 3 then
		dmgScript.Parent = char["Right Leg"]
	end
	dmgScript.Disabled = false
	wait(0.4)
	dmgScript:Destroy()
end

punchEvent.OnServerEvent:Connect(onPunchFired)
---------------

6 comments

0

When you die, wouldn't the descendants of the character disappear?

0

Yeah but the script even fails after players join after someone who used the combat

0

Any errors?

0

Nope But The Remote Event Keeps Being Made over and over again when the combat is trying to be used

0

Not quite sure what the issue could be, but you could try changing the char variable to plr.Character and then make sure 'Char' and 'Humanoid' exist after that

0

From what I see I think there might be some sort of “stalling” which just pauses the scripts for some reason. :WaitForChild() Could be the main issue, also you don’t need to use :WaitForChild() on Remotes since they load super fast.