Gun doesn't work properly if cloned into player's backpack

Gun doesn’t work properly if cloned into player’s backpack, but works if player picks up the gun, it works perfectly fine.
I have no clue how to mitigate the issue.

me using a quick button i made to clone a rifle to my backpack; then it proceeding to break
https://i.gyazo.com/f16f400db7ed3f39e8e4b1017462d03a.mp4

a snippet of the server script i use.

local replicatedStorage = game:GetService("ReplicatedStorage")

local fireGunEvent = replicatedStorage.FireGun
local reloadingSFXevent = replicatedStorage.ReloadingSFX

fireGunEvent.OnServerEvent:Connect(function(player, rifle, startPos, endPos)
	local gunshotSFX = rifle.Handle.GunShot
	local reloadSFX = rifle.Handle.Reload
	
	local particles = rifle.Barrels.MuzzleFX:GetChildren()
	
	local headShotDamage = rifle:GetAttribute("HeadshotDamage")
    local MaxDistance = rifle:GetAttribute("MaxDistance")
	local Damage = rifle:GetAttribute("Damage")
	
	local direction = (endPos - startPos).Unit * MaxDistance
	
	local raycastRes = game.Workspace:Raycast(startPos, direction)
	
	gunshotSFX:Play()
	
	for i, particles in ipairs(particles) do
		task.spawn(function()
			particles:Emit()
		end)
	end

eureka i figured it out !!!

Could you perhaps share how exactly you fixed this issue? It would help Developers who might be facing the same issue.

1 Like

Of course! I just had to use a remote event that was fired in the buttons local script when the button was pressed to connect a function on a server script to actually give the rifle by the server, rather than handling everything locally.

2 Likes

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