Aiming System with Player Arms?

Hi,
So a while back, I have made Topic’s asking for help with Aiming Weapons with the Players Arms, I Had already made the aiming system, problem was, it wasn’t replicating on the Server

Another Issue was that people seem to confuse Player Arms with FPS Arms
A Couple of people were explaining about how to use a Framework, but that’s not what I wanted nor did i say anything about me needing assistance with Framework besides collusion.

But Someone finally Helped created this script which i modified:

local Tool = script.Parent
local GS = require(script.Parent.WeaponSetup)
local Players = game:GetService('Players')
local toggleScopeRemoteEvent = game.ReplicatedStorage.Aim
local A = GS.Player.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.Client:WaitForChild("Aim"))

local aiming = false

local function playerAdded(player: Player)
	local function updateScopingForPlayer(plr, isAiming)
		if aiming == true then
		A:Play()
			Tool.Client:WaitForChild("Fire").AnimationId = GS.AimFireAnimation
			
			GS.TweenService:Create(GS.Camera, TweenInfo.new(0.2, Enum.EasingStyle.Sine), {FieldOfView = 40}):Play()
			GS.TweenService:Create(GS.Lighting.DepthOfField, TweenInfo.new(0.2, Enum.EasingStyle.Sine), {FarIntensity = 1}):Play()
		elseif aiming == false then
			A:Stop()
			Tool.Client:WaitForChild("Fire").AnimationId = GS.FireAnimation
		
			GS.TweenService:Create(GS.Camera, TweenInfo.new(0.2, Enum.EasingStyle.Sine), {FieldOfView = 120}):Play()
			GS.TweenService:Create(GS.Lighting.DepthOfField, TweenInfo.new(0.2, Enum.EasingStyle.Sine), {FarIntensity = 0}):Play()
		end
	end

	local isAiming = player:GetAttribute("Aiming")==true
	updateScopingForPlayer(player, isAiming)

	player:GetAttributeChangedSignal("Aiming"):Connect(function()
		local isAiming = player:GetAttribute("Aiming")== aiming
		updateScopingForPlayer(player, isAiming)
	end)
end

GS.UserInputService.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.Q and aiming == false then
		aiming = true
		
		toggleScopeRemoteEvent:FireServer(aiming)
	end
end)
GS.UserInputService.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.Q and aiming == true then
		aiming = false

		toggleScopeRemoteEvent:FireServer(aiming)
	end
end)

GS.Tool.Equipped:Connect(function()
	aiming = false	
end)

GS.Tool.Unequipped:Connect(function()
	
	A:Stop()

	aiming = nil
	GS.Client.Idle.AnimationId = GS.IdleAnimation
		GS.TweenService:Create(GS.Camera, TweenInfo.new(0.2, Enum.EasingStyle.Sine), {FieldOfView = 120}):Play()
		GS.TweenService:Create(GS.Lighting.DepthOfField, TweenInfo.new(0.2, Enum.EasingStyle.Sine), {FarIntensity = 0}):Play()
	script.Enabled = false

end)

for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
	playerAdded(player)
end

Players.PlayerAdded:Connect(playerAdded)

It works, but not the exact way I want it to, Is there a more simpler way of doing this? or at least a better alternative?

2 Likes

What is the exact way you want? What does it do currently?

Please Re-read my Post…

An Aiming System, Player Arms, Not Replicating on Server, Someone Helped, Is there a better way of doing this?

For this to replicate you need to tell all clients that the animation has happened. Usually this entails send an event to the server, which then sends the event to all clients except the original sender (or does send it to the original sender, who must ignore it) so the animation doesn’t appear to start twice.

As for a better way to do it, theres no way to know that without a criteria for what you want improved. If you mean simpler / less code, no, it doesn’t look like it.

I have Used RemoteEvents to sent data from the Client to the Server and Vice Versa, But i dont get a different result, everything works, but not the Animations, the Only animations that work are the weapon animations used when firing the weapon and the idle animations

When player B fires an animation, player A needs that animation to have its :Play() called on player A’s computer, since your code runs in a local script, you need to send an event telling player A that the animation needs fired. The simplest solution involves at least one additional server script which just receives the client-to-server event from player B and sends it to player A.

Once again, i have tried this, got the same result

Ok, show the code?

character limit

This is the code, the other code i have removed a long time ago.

I have said that someone helped, but I’m not getting the result I want

I swear, nobody reads my post fully

If this is the only code involved then there is no mechanism to signal other clients. Do you think that you don’t need Remotes to do this?

It is possible that you can Create this without RemoteEvents, but I perfer RemoteEvents

I Plan on rewriting my Weapon System, so i’ll try your solutions when i get back, wont be for a while

Then where is the server code to receive the remote events? Is that the code you removed?

All of this is kinda old btw:

local Tool = script.Parent
local GS = require(Tool.WeaponSetup)


local function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	GS.Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

local function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

script.Parent.Fire.OnServerEvent:Connect(function(plr,mousepos)
	
	local Sound = Instance.new("Sound",Tool.Handle)
	Sound.PlaybackSpeed = 1
	Sound.Volume = 2
	Sound.SoundId = GS.FireSound
	Sound:Play()
	GS.Debris:AddItem(Sound, 2)
	local RCP = RaycastParams.new()
	RCP.FilterDescendantsInstances = {plr.Character}
	RCP.FilterType = Enum.RaycastFilterType.Blacklist

	local RCR = workspace:Raycast(Tool.Handle.Position, (mousepos - script.Parent.Handle.Position) * 300,RCP)


	if RCR then
		local HP = RCR.Instance
		local model = HP:FindFirstAncestorOfClass("Model")


		if model then
			if model:FindFirstChild("ZHumanoid") then
				TagHumanoid(model.ZHumanoid, plr)
				model.ZHumanoid:TakeDamage(GS.Damage)
				local FS = Instance.new("Sound", model.Torso)
				FS.SoundId = GS.FleshHitSound
				FS:Play()
				GS.Debris:AddItem(FS, 2)
			end

		end	

	end
--[[ This Part of the script is OLD
	Tool.Handle.Flash.Light.Enabled = true
	Tool.Handle.Flash.MuzzleEffect.Enabled = true
	wait()
	Tool.Handle.Flash.Light.Enabled = false
	Tool.Handle.Flash.MuzzleEffect.Enabled = false
]]
end)

local toggleScopeRemoteEvent = game.ReplicatedStorage.Aim

toggleScopeRemoteEvent.OnServerEvent:Connect(function(player, isAiming)
	player:SetAttribute("Aiming", isAiming)
end)

making a new system rn

The last three lines of this are essential for your aiming to be replicated. It uses the fact that Attributes are replicated to inform the other clients. There are probably other problems with the client side code, in particular I think A:Play() is wrong, because its using a variable from outside the function, but without that last bit of server code it can’t work period.

I know that, but the problem is i’m getting the result i want

@azqjanna

So i found out why my Aiming wasn’t working with other code, I was accidentally changing the AnimationId’s on the Client, Since the changes don’t replicate on the server, nothing happened, that’s why it wasn’t working, thanks for helping tho

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