Weapons Kit - Shoulder Camera

Sorry to bump this in late, but Friendly Fire/Team Killing does not seem to work. I tried adding string values in every player character, which did work, but I could still kill my teammates. There were only 2 methods that gave the string values in every player character, and here are the scripts:
Method 1 (ServerScriptService):

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local RedColor = BrickColor.new("Really red")
		local BlueColor = BrickColor.new("Toothpaste")
		
		if plr.TeamColor == RedColor then
			local RedString = Instance.new("StringValue", char)
			RedString.Name = "Role"
			RedString.Value = "Red"
			
		elseif plr.TeamColor == BlueColor then
			local BlueString = Instance.new("StringValue", char)
			BlueString.Name = "Role"
			BlueString.Value = "Blue"
		end
	end)
end)

Method 2 (StarterCharacterScripts):

local Teams = game:GetService("Teams")
local RedTeam = Teams.RedTeam
local BlueTeam = Teams.BlueTeam

local RedColour = BrickColor.new("Really red")
local BlueColour = BrickColor.new("Toothpaste")

for _, redPlr in pairs(RedTeam:GetPlayers()) do
	local redChar = redPlr.Character
	
	if redPlr.TeamColor == RedColour then
		local RedString = Instance.new("StringValue", redChar)
		RedString.Name = "Role"
		RedString.Value = "Red"
	end
end

for _, bluePlr in pairs(BlueTeam:GetPlayers()) do
	local blueChar = bluePlr.Character
	
	if bluePlr.TeamColor == BlueColour then
		local BlueString = Instance.new("StringValue", blueChar)
		BlueString.Name = "Role"
		BlueString.Value = "Blue"
	end
end

I’m really not sure if i did something wrong, because I can see the string value in the character with the correct name and value. I’ve been struggling with this for a while now. Any help is appreciated.

5 Likes

@DevRelationsTeam
I love to see how much time the Community is spending to debug and optimize these features.
What I find disheartening is the fact that Roblox seems to be absent in this process.

The result is one of the most inefficient, anti-patterns of modern programming:
Multiple parties create a variety of parallel home grown solutions which are never merged into the main branch.

If we all adopt @Thundemaker 's solution, what happens when Roblox revs their branch?

It would be really great to see some git-like process where specific Issues are identified, tracked, resolved, and merged into the main branch at Roblox HQ.

This would, of course, require a layer of management to consolidate and track the issues, but this is what modern companies do, and what make them efficient. These Community members are making your product better for free. It’s worth the expense to extend the same source code control tools to them that you use internally.

Does this process exist, and I just don’t know about it?
For example, is there some public facing Feature Request queue that captures the fact that Roblox is working on a Shoulder Camera solution? If so, that would help sync the efforts of Roblox and the Community.

8 Likes

they did not finish the teamkill function from what I saw, or at least did not code it to be compatible with any common definition of teams- under the weaponsSystem script find the function "WeaponsSystem.playersonDifferentTeams- here you will need to modify the code to check if player1 and player 2 are on different teams per your specific implementation of teams. Even after you fix this there may be one type of damage (Explosion splash damage) that still doesn’t run through this function…I forget, but I had to make a number of changes to truly fix the teamkilling using this kit.

4 Likes

Could you please be more specific in the way of how to fix the teamkilling issue?

2 Likes

I would suggest making your own weapons instead of using these. Making some simple guns is easy as hell, believe me. Plus you would have full control over how they work, and you can change anything anytime.

2 Likes

There does seem to be a tagHumanoid function inside the WeaponsSystem module, you would just need to make a separate server script to detect when a humanoid dies and if they have a creator tag on them.

1 Like

I would anyway recommend making your own gun system over these kind of fancy guns. Its very easy, believe me! You would waste more time in fixing these guns rather than making your own.

I made the changes recommended here and for the most part the camera now works with and without a weapon being equipped. One situation that is still glitchy is when you try to drive a vehicle (such as the Roblox Dune Buggy). If you enter the driver’s seat while you have a weapon equipped the result is not good. Any suggestions on how to fix this? I would think you would just want to unequip the weapon when you enter the vehicle.

Just unequip any tool that is currently equipped when a player enters a vehicle using Humanoid:UnequipTools().

2 Likes

I modified this function in the WeaponsSystem ModuleScript to keep players on the same team from shooting each other:

function WeaponsSystem.doDamage(target, amount, damageType, dealer, hitInfo, damageData)
	if not target or ancestorHasTag(target, "WeaponsSystemIgnore") then
		return
	end
	if IsServer then
		if target:IsA("Humanoid") and dealer:IsA("Player") and dealer.Character then
			local dealerHumanoid = dealer.Character:FindFirstChildOfClass("Humanoid")
			local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
			-- Jaxxon Jargon: added check so players on the same team can't kill each other.
			if WeaponsSystem.playersOnDifferentTeams(dealer, targetPlayer) then
				if dealerHumanoid and target ~= dealerHumanoid and targetPlayer then
					-- Trigger the damage indicator
					WeaponData:FireClient(targetPlayer, "HitByOtherPlayer", dealer.Character.HumanoidRootPart.CFrame.Position)
					targetPlayer.Character.Humanoid:TakeDamage(amount)
				end
			end
		end

		-- NOTE:  damageData is a more or less free-form parameter that can be used for passing information from the code that is dealing damage about the cause.
		-- .The most obvious usage is extracting icons from the various weapon types (in which case a weapon instance would likely be passed in)
		-- ..The default weapons pass in that data
		local handler = _damageCallback or _defaultDamageCallback
		handler(WeaponsSystem, target, amount, damageType, dealer, hitInfo, damageData)
	end
end

You’ll also need to modify the following function:

local function _defaultGetTeamCallback(player)
	return player.Team or 0
end

Let me know if this works for you or not.

3 Likes

Working perfectly! Thanks you :smiley:

How can I activate friendly fire? so that a team can kill each other?

not sure I follow your question- I think it ignores teams and allows you to damage everyone by default. if you want to have both options, then after you implemented the fix to not hurt teammates, you’d probably add a variable “friendlyFire” that is either true or false and add it as a check in the “playersOnDifferentTeams” function. Then you’d need some GUI to toggle/set the value of that variable

Hi all, I am currently using a heavily modified version of the endorsed weapons kit for my game, but I am running into an issue that is also present in the weapons kit files in this thread.

Essentially, when you unequip a weapon while zoomed in, the camera maintains the field of view values it had while zoomed. It is not very noticeable with weapons that have sights (FOV changes from 70->65, which is barely noticeable), but if you try it with a weapon with a bigger ZoomFactor like the Sniper Rifle, then it becomes apparent.

Like I mentioned, this issue is also present in the files previously attached to this thread. Any idea how to fix this?

1 Like

Was actually able to figure this out. Essentially what is happening is the zoomFactor functions are being called correctly, but on unequip the main ShoulderCamera loop is not updating the camera to reflect the updated zoom numbers.

Within ShoulderCamera, there is a function “setEnabled”. If you go into the else statement in this function (which is called when setEnabled is false on unequip), you can add the SpringService line of code so the camera will update with the new zoom factor after unequipping. The code should look like this:

ShoulderCamera.SpringService:Target(self, 0.8, 3, { zoomAlpha = self.zoomState and 1 or 0 })
ShoulderCamera.SpringService:Target(self.currentCamera, 0.8, 3, { FieldOfView = self.desiredFieldOfView })

2 Likes

Here’s a better solution to the character tilting problem…

I wanted to keep the applyRootJointFix() function as the weapon bouncing up and down looks just as bad as the character tilting.

Add a new attribute to the ShoulderCamera constructor: e.g. self.tiltFix, and initialise to nil.

Now, inside applyRootJointFix(), before this line…

self.rootJoint.C0 = CFrame.new(self.rootJoint.C0.Position, self.rootJoint.C0.Position + rotationFix.LookVector.Unit)

add this line, so that we have the original C0 CFrame value stored.

if not self.tiltFix then self.tiltFix = self.rootJoint.C0 end

Now, when the weapon is unequipped, set rootJoint.C0 to the tiltFix CFrame value. For example, I have this line in a LocalScript, connected to the Unequipped event:

weaponModule.camera.rootJoint.C0 = weaponModule.camera.tiltFix
3 Likes

which tilting issue is this referring to?

1 Like

I made a video about this, it includes:

  1. Shoulder camera fixed
  2. With and without FriendlyFire Scripts
  3. Cash per kill

Here’s a link: Roblox Studio | Weapon Kit FREE Model(Camera Bug Fixed, AmmoUI, FriendlyFire, and Cash Per Kill) - YouTube

5 Likes

can someone upload a model with the friendly fire fix? I tried adding a stringvalue on the character but then it just disappears

1 Like

This is an old post, but I made a complete fix Free Model for the Weapons Kit for anyone trying to search for how to fix it. It also fixes some other issues that have not previously been mentioned in this thread.

Roblox Weapons Kit Fix - Resources / Community Resources - Developer Forum | Roblox

Roblox Weapon Kit Fix Asset

1 Like