Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I prevent people from shooting after they are killed?

For some reason, people can shoot as long as their weapon is still equipped even after they die but before they respawn. How do I prevent that? Here is my WeaponServerScript:

--Version: 4.3.1
print("Loading weapons RFs")

local Ignore_Model = workspace:FindFirstChild("Ignore_Model") or Instance.new("Model",workspace)
Ignore_Model.Name = "Ignore_Model"

ShootRF = script:WaitForChild("Shoot")
FakeArmsRF = script:WaitForChild("FakeArms")
FakeArmsRemoveRF = script:WaitForChild("FakeArmsRemove")
SetNeckRE = script:WaitForChild("SetNeck")
AimRF = script:WaitForChild("Aim")
ReloadingAnimationRF = script:WaitForChild("ReloadingAnimation")
SprintRE = script:WaitForChild("Sprint")
Debris = game:GetService("Debris")

function ItsKill(Player,Killed,Wpn,Headshot,Distance)
	print(Player.Name.." killed "..Killed.Name.." with "..Wpn.." from "..math.floor(Distance/0.1)*0.1 .." studs")
end

ShootRF.OnServerEvent:connect(function(Player,StartPos,EndPos,HitPlayer,Damage,Wpn,IsHeadshot,BSP)
	if not StartPos or not EndPos then return false end
	local Distance = (StartPos-EndPos).magnitude
	if HitPlayer then
		if HitPlayer.Character.Humanoid.Health <= Damage and HitPlayer.Character.Humanoid.Health > 0 then
			HitPlayer.Character.Humanoid.Health = 0
			ItsKill(Player,HitPlayer,Wpn,IsHeadshot,Distance)
		else
			HitPlayer.Character.Humanoid.Health = HitPlayer.Character.Humanoid.Health - Damage
		end
	end
	--Sound
	if BSP then
		local Sound = BSP.Sound
		local Sound = Sound:Clone()
		Sound.Parent = BSP
		if Sound then Sound:Play() end
		Debris:AddItem(Sound,Sound.TimeLength)
	end
	--Creating bullet tracer
	local rayPart = Instance.new("Part")
	rayPart.Parent = Ignore_Model
	rayPart.Name = "RayPart"
	rayPart.BrickColor = BrickColor.new("Meduim stone grey")
	rayPart.Transparency = 0.85
	rayPart.Anchored = true
	rayPart.CanCollide = false
	rayPart.TopSurface = Enum.SurfaceType.Smooth
	rayPart.BottomSurface = Enum.SurfaceType.Smooth
	rayPart.Size = Vector3.new(0.2, 0.2, Distance-10)
	rayPart.CFrame = CFrame.new(EndPos, StartPos) * CFrame.new(0, 0, -Distance/2)
	rayPart.CFrame = rayPart.CFrame * CFrame.new(0,0,10)
	Debris:AddItem(rayPart, 0.45)
end)

function FakeArmsRF.OnServerInvoke(Player,LeftPos,RightPos)
	local PChar = Player.Character
	local Left_Weld,Right_Weld
	local Right_Arm, Left_Arm, Torso
	local isR15 = false
	if PChar then
		Torso = PChar:FindFirstChild("Torso")
		if not Torso then
			Torso = PChar:FindFirstChild("UpperTorso")
			if Torso then
				isR15 = true
				Right_Arm = PChar:FindFirstChild("RightUpperArm")
				Left_Arm = PChar:FindFirstChild("LeftUpperArm")
			else
				error("Character's Torso is not found.")
			end
		end
		
		Left_Weld = Instance.new("Weld", Torso)
		Left_Weld.Name = "Left_Weld"
		Left_Weld.Part0 = PChar.Head
		if isR15 then
			Left_Weld.C0 = CFrame.new(0.1, -1.8, 0)
		else
			Left_Weld.C0 = CFrame.new(0, -1.5, 0)
		end
		if isR15 then
			Left_Arm["LeftShoulder"].Part1 = nil
			Left_Weld.Part1 = Left_Arm
		else
			Torso["Left Shoulder"].Part1 = nil
			Left_Weld.Part1 = PChar["Left Arm"]
		end
		
		Right_Weld = Instance.new("Weld", Torso)
		Right_Weld.Name = "Right_Weld"
		Right_Weld.Part0 = PChar.Head
		if isR15 then
			Right_Arm["RightShoulder"].Part1 = nil
			Right_Weld.Part1 = Right_Arm
		else
			Torso["Right Shoulder"].Part1 = nil
			Right_Weld.Part1 = PChar["Right Arm"]
		end
		if isR15 then
			Right_Weld.C0 = CFrame.new(0.55, -1.8, 0.5)
		else
			Right_Weld.C0 = CFrame.new(0, -1.5, 0)
		end
		Left_Weld.C1 = LeftPos
		Right_Weld.C1 = RightPos
	end
	local FixedArm,FixedArmWeld,FixedArmModel
	--Fixed Arm
	print("Fixing arm(Aiming)")
	if isR15 then
		FixedArm = Right_Arm:Clone()
	else
		FixedArm = PChar["Right Arm"]:Clone()
		FixedArm.Size = Vector3.new(1,2,1)
	end
	FixedArmWeld =  Instance.new("Weld", FixedArm)
	FixedArmWeld.Part0 = PChar.Head
	FixedArmWeld.Part1 = FixedArm
	FixedArmModel = Instance.new("Model",Ignore_Model)	
	for i, v in pairs(PChar:GetChildren()) do
		if v:IsA("CharacterMesh") and v.BodyPart == Enum.BodyPart.LeftArm or v:IsA("CharacterMesh") and v.BodyPart == Enum.BodyPart.RightArm then
			v:Clone().Parent = FixedArmModel
		end
	end
	if PChar:FindFirstChild("Shirt") then
		local Humanoid = Instance.new("Humanoid")
		Humanoid.Parent = FixedArmModel
		if isR15 then
			Humanoid.RigType = "R15"
		else
			Humanoid.RigType = "R6"
		end
		PChar.Shirt:Clone().Parent = FixedArmModel
	end
	FixedArm.Transparency = 1
	FixedArm.Parent = FixedArmModel
	FixedArmWeld.C1 = CFrame.new(-1, 0.5, -1) * CFrame.Angles(math.rad(-85), math.rad(-40), 0)
	
	return Left_Weld,Right_Weld,FixedArm,FixedArmWeld,FixedArmModel
end

function FakeArmsRemoveRF.OnServerInvoke(Player)
	local PChar = Player.Character
	if not PChar then return error("Character is not found") end
	local Torso = PChar:FindFirstChild("Torso")
	if not Torso then
		Torso = PChar:FindFirstChild("UpperTorso")
		if not Torso then return error("Character's Torso is not found") end
		local Right_Arm,Left_Arm = PChar:FindFirstChild("RightUpperArm"),PChar:FindFirstChild("LeftUpperArm")
		Right_Arm["RightShoulder"].Part1 = Right_Arm
		Left_Arm["LeftShoulder"].Part1 = Left_Arm
	else
		Torso["Right Shoulder"].Part1, Torso["Left Shoulder"].Part1 = PChar["Right Arm"], PChar["Left Arm"]
	end
	local LW = Torso:FindFirstChild("Left_Weld")
	if LW then LW:Destroy() end
	local RW = Torso:FindFirstChild("Right_Weld")
	if RW then RW:Destroy() end
	local FixedArmModel = Ignore_Model:FindFirstChild(Player.Name)
	if FixedArmModel then
		FixedArmModel:Destroy()
	end
end

SetNeckRE.OnServerEvent:connect(function(Player,Angles)
	SetNeckRE:FireAllClients(Player,Angles)
end)

AimRF.OnServerEvent:connect(function(Player,InOut,AimPart,LeftAimPos,AimGrip,RightPos,LeftPos)
	AimRF:FireAllClients(Player,InOut,AimPart,LeftAimPos,AimGrip,RightPos,LeftPos)
end)

script.HitNotAnchored.OnServerEvent:connect(function(Player,Hit,VelAng)
	local v = Instance.new("BodyVelocity",Hit)
	v.maxForce = Vector3.new(4000,4000,4000)
	v.velocity = VelAng*Vector3.new(15,15,15)
	wait(0.01)
	v:remove()
end)

script.DestroyObject.OnServerEvent:connect(function(_,Hit)
	if Hit.Name == "Glass" then
		Hit.Anchored = false
		Hit:BreakJoints()
	elseif Hit.Name == "Glass" then
		Hit:Destroy()
	end
end)

ReloadingAnimationRF.OnServerEvent:connect(function(Player,Gun,RightPos)
	ReloadingAnimationRF:FireAllClients(Player,Gun,RightPos)
end)

SprintRE.OnServerEvent:connect(function(Player,InOut,Speed,Type,RightPos,LeftPos)
	if Player and Player.Character then
		Player.Character.Humanoid.WalkSpeed = Speed
		SprintRE:FireAllClients(Player,InOut,Speed,Type,RightPos,LeftPos)
	end
end)

print("Weapon server-side script loaded")

1 answer

Just check to make sure the player shooting has health above 0 before firing the remote event to the server.

3 comments

0

how would i do that tho

1

do if (variable for your player).Health ~= 0 then

0

rest of your code

This discussion is preserved as it was. New answers, comments, and votes are closed.