My gun doesnt work

My problem is that i created a gun and put in into starter pack because i wanted to test it. Later, i created a button that teleports player into arena and gives him that gun. But then i realised that that gun doesnt work. I do not know why.

Problem script:

script.Parent.Fire.OnServerEvent:Connect(function(player, mousepos)

	local raycastparams = RaycastParams.new()
	raycastparams.FilterDescendantsInstances = {player.character}
	raycastparams.FilterType = Enum.RaycastFilterType.Blacklist

	local raycastResult = workspace:Raycast(script.Parent.Handle.Position, (mousepos - script.Parent.Handle.Position)*300,raycastparams)

	if raycastResult then
		local hitpart = raycastResult.Instance
		local model = hitpart:FindFirstAncestorOfClass("Model")
		
		if model then
			if model:FindFirstChild("IsPlayer") then
				model.Humanoid.Health -= 25
				script.Parent.Sound:Play()
				if model.Humanoid.Health == 0 then
					local char = script.Parent.Parent
					local plr = game.Players:GetPlayerFromCharacter(char)
					plr.leaderstats.Credits.Value += 5
				end
			end
		end	
	end
end)

Try using prints on your to see where it does not work.

2 Likes