Gun Script Error

I want it to able to kill a player but can also kill a zombie free model by roblox

local system = {
	["PLAYERNAME"] = nil,
	["SELFPLAYERNAME"] = nil
}

system.CAST = function(plr:Player)
	local MOUSE = plr:GetMouse()
	system.SELFPLAYERNAME = plr.Character.Name
	MOUSE.Button1Down:Connect(function()
		local SELF = nil
		local WORLD_CAMERA = workspace.CurrentCamera
		local RAY_PARAMS = RaycastParams.new()
		RAY_PARAMS.IgnoreWater = true
		RAY_PARAMS.FilterType = Enum.RaycastFilterType.Exclude
		RAY_PARAMS.FilterDescendantsInstances = {script.Parent, plr.Character}
		local LOOK_CAMERA = WORLD_CAMERA.CFrame.LookVector
		local RAY_RESULT = workspace:Raycast(WORLD_CAMERA.CFrame.Position, WORLD_CAMERA.CFrame.LookVector * 23, RAY_PARAMS)
		print(RAY_RESULT.Instance.Name)
		system.PLAYERNAME = plr.Name
		RAY_RESULT.Instance.Color = Color3.new(1,1,1)
		if plr.Name == system.SELFPLAYERNAME then
			print("|| Not Available ||")
		else	
			system.DAMAGE_PLAYER(plr)
		end
	end)
end

system.DAMAGE_PLAYER = function(plr:Player)
	local CHAR = workspace:WaitForChild(system.PLAYERNAME)
	CHAR.Humanoid.Health = 0
end

return system

Thanks in advance

3 Likes

I believe what the script is doing is detecting whether the ray hits another player that isn’t yourself.

Instead, you should probably check whether the ray_result hits something with a humanoid and checks whether the humanoid belongs to a player and/or a zombie.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.