Need help with Guns on other devices!

Hey Developers! I am making a Gun system on my game, and my guns do work on PC/Computer. But it does not work on Xbox and phone/IPad’s, and I’m worried to lose players. How can I fix this problem?

Client:

wait(0.1)

local anim1 = Instance.new("Animation")
anim1.AnimationId = "rbxassetid://10047693743" --Hold

local anim2 = Instance.new("Animation")
anim2.AnimationId = "rbxassetid://10047698940" --Fire

local anim3 = Instance.new("Animation")
anim3.AnimationId = "rbxassetid://10047691350" --Reload

local anim4 = Instance.new("Animation")
anim4.AnimationId = "rbxassetid://9723155799" --Safe Mode

local track1
local track2
local track3
local track4

local runservice = game:GetService('RunService')
local uis = game:GetService('UserInputService')
local camera = game.Workspace.CurrentCamera
local player = game:GetService('Players').LocalPlayer
local mouse = player:GetMouse()
local configuration = require(script.Parent.Settings)
local ammo = configuration.Ammo
local mag = configuration.Mag
local ammogui = script.Ammogui
local db = false
local shooting = false
local safemode = false
local oldmouse

equipped = false

-----------------Functions-----------------

local function UpdateGui()
	ammogui.TextLabel.Text = ammo..' / '..mag
	ammogui.GunName.Text = configuration.WeaponName
end

local function CameraRecoil()	
	runservice.RenderStepped:Wait()
	local randomy = (math.random(0,configuration.Recoil*2)-configuration.Recoil)/1200

	if game.Workspace.CurrentCamera.CFrame.LookVector.Y < 0.9 then
		game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame*CFrame.Angles(configuration.Recoil/360/2,randomy/4,math.random(-0.9,0.9))
		runservice.RenderStepped:Wait()
		game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame*CFrame.Angles(configuration.Recoil/360/2,randomy/4,math.random(-0.9,0.9))
	else
		runservice.RenderStepped:Wait()
	end

	local value = 0
	for i=0.01,1,-1 do
		game["Run Service"].RenderStepped:Wait()
	game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame*CFrame.Angles(-configuration.Recoil/7200*i/14,randomy/40*i/10,math.random(-0.9,0.9))
		value = value + i/10
	end
	return true

end

-----------------Shoot-----------------

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		if shooting then
			shooting = false
		end
	end
end)

uis.InputBegan:Connect(function(input)
	if configuration.Auto == true then
		if equipped == true then
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				if shooting == false then
					if safemode == false then
						if db == false then
							if ammo > 0 then
								shooting = true
								repeat
									db = true
									ammo = ammo - 1
									mouse.TargetFilter = workspace.Bullets
									script.Parent.Shot:FireServer(mouse.Hit.p)
									track2 = script.Parent.Parent.Humanoid:LoadAnimation(anim2)
									track2.Priority = Enum.AnimationPriority.Action2
									track2.Looped = false
									track2:Play()
									CameraRecoil()
									UpdateGui()
									task.wait(.01)
									wait(configuration.FireRate)
									db = false
								until shooting == false or ammo == 0 or equipped == false or safemode == true
							end
						end
					end
				end
			end
		end
	else
		if equipped == true then
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				if shooting == false then
					if safemode == false then
						if db == false then
							if ammo > 0 then
								db = true
								ammo = ammo - 1
								mouse.TargetFilter = workspace.Bullets
								script.Parent.Shot:FireServer(mouse.Hit.p)
								track2 = script.Parent.Parent.Humanoid:LoadAnimation(anim2)
								track2.Priority = Enum.AnimationPriority.Action2
								track2.Looped = false
								track2:Play()
								CameraRecoil()
								UpdateGui()
								task.wait(.01)
								wait(configuration.FireRate)
								db = false
							end
						end
					end
				end
			end
		end
	end
end)

-----------------Reload-----------------

uis.InputBegan:Connect(function(input)
	if input.KeyCode == configuration.ReloadKey then
		if equipped == true then
			if safemode == false then
				track3 = script.Parent.Parent.Humanoid:LoadAnimation(anim3)
				track3.Priority = Enum.AnimationPriority.Action
				track3.Looped = false
				track3:Play()
				ammogui.TextLabel.Text = 'Reloading'
				equipped = false
				script.Parent.Handle.Reload:Play()
				wait(configuration.ReloadTime)
				equipped = true
				ammo = mag
				UpdateGui()
			end
		end
	end
end)

-----------------Safe Mode-----------------

uis.InputBegan:Connect(function(input)
	if configuration.SafeMode == true then
		if input.KeyCode == configuration.SafeModeKey then
			if db == false then
				if equipped == true then
					if safemode == false then
						safemode = true
						track4 = script.Parent.Parent.Humanoid:LoadAnimation(anim4)
						track4.Priority = Enum.AnimationPriority.Action
						track4.Looped = true
						track4:Play()
					else
						db = true
						safemode = false
						if track4 then
							track4:Stop()
						end
						wait(0.3)
						db = false
					end
				end
			end
		end
	end
end)

-----------------Equip Unequipped-----------------

script.Parent.Equipped:Connect(function()
	db = true
	equipped = true
	ammogui.Parent = player.PlayerGui
	UpdateGui()

	oldmouse = mouse.Icon
	mouse.Icon = configuration.MouseIcon

	track1 = script.Parent.Parent.Humanoid:LoadAnimation(anim1)
	track1.Priority = Enum.AnimationPriority.Action
	track1.Looped = true
	track1:Play()
	script.Parent.Handle.Equip:Play()
	wait(configuration.EquipTime)
	db = false
end)

script.Parent.Unequipped:Connect(function()
	ammogui.Parent = script
	mouse.Icon = oldmouse
	equipped = false
	safemode = false
	if track1 then
		track1:Stop()
	end
	if track2 then
		track2:Stop()
	end
	if track3 then
		track3:Stop()
	end
	if track4 then
		track4:Stop()
	end
end)

Server:

local configuration = require(script.Parent.Settings)
local debris = game:GetService('Debris')

equipped = false
script.Parent.Equipped:Connect(function()
	equipped = true
end)
script.Parent.Unequipped:Connect(function()
	equipped = false
end)

----------dont change-----------
local fired = false
local firedTime = 0
local eventTime = 0
local fireRate = 0
--------------------------------

function countCheck()
	if firedTime-eventTime >= fireRate or fireRate-(firedTime-eventTime) <= 1/60 then
		return true
	end
end
script.Parent.Shot.OnServerEvent:Connect(function(player,mousePos)
	if not player.Character == script.Parent.Parent then return end
	
	firedTime = tick()
	if equipped and countCheck() then
		eventTime = tick()
		script.Parent.Handle.Fire:Play()
		script.Parent.Handle.Attachment.PointLight.Enabled = true
		script.Parent.Handle.Attachment.MuzzleFlash.Enabled = true
		script.Parent.Handle.Attachment.MuzzleSmoke.Enabled = true
		for bulletCount = 1, configuration.Bullets do
			task.spawn(fire,player,mousePos)
		end
		wait(0.05)
		script.Parent.Handle.Attachment.MuzzleFlash.Enabled = false
		script.Parent.Handle.Attachment.MuzzleSmoke.Enabled = false
	elseif fired == false then
		fired = true
		task.wait(fireRate-(firedTime-eventTime))
		fired = false
	end
end)

function newBullet()
	local bullet = game.ReplicatedStorage.GunSystem.Bullet:Clone()
	bullet.Position = script.Parent.Fire.Position
	bullet.CanCollide = false
	bullet.CastShadow = false
	bullet.Size = Vector3.new(1,1,1)
	bullet.Name = "bullet"
	bullet.Transparency = 1
	bullet.Parent = workspace.Bullets
	bullet:SetNetworkOwner(nil)
	return bullet
end

function changeGravity(bullet,mass)
	local lift = Instance.new("VectorForce",bullet)
	lift.Force = Vector3.new(0,mass*game.Workspace.Gravity,0) --gravity
	local attachment = Instance.new("Attachment",bullet)
	lift.RelativeTo = Enum.ActuatorRelativeTo.World
	lift.ApplyAtCenterOfMass = true
	lift.Attachment0 = attachment
end

function applyPhysics(bullet,mousePos)
	local muzzleVelocity = configuration.BulletVelocity
	local direction = CFrame.new(bullet.Position,mousePos)
	
	local verticalSpread = configuration.Spread
	local horizontalSpread = configuration.Spread
	local rng = Random.new()
	verticalSpread = rng:NextNumber(-verticalSpread,verticalSpread)
	horizontalSpread = rng:NextNumber(-horizontalSpread,horizontalSpread)
								
	verticalSpread = math.rad(verticalSpread)
	horizontalSpread = math.rad(horizontalSpread)
	direction = direction*CFrame.Angles(verticalSpread,horizontalSpread,0)
	direction = direction.LookVector
	
	local mass = bullet:GetMass()
	bullet:ApplyImpulse(direction * mass * muzzleVelocity)
	
	changeGravity(bullet,mass)
end

function rayFilter(player)
	local rayFilter = RaycastParams.new()
	rayFilter.FilterDescendantsInstances = {player.Character,workspace.Bullets,workspace.NoCollide}
	rayFilter.FilterType = Enum.RaycastFilterType.Blacklist
	return rayFilter
end

function updateTracer(tracer,lastPos,rayPos)
	tracer.Size = Vector3.new(.1, .1, (lastPos-rayPos).magnitude)
	tracer.CFrame = CFrame.new(rayPos,lastPos)*CFrame.new(0, 0, -(lastPos-rayPos).magnitude/2)
end

function shellejection()
	if configuration.ShellType == 1 then
		local shell = game.ReplicatedStorage.GunSystem.Shell1:Clone()
		shell.CFrame =  script.Parent.Ejection.CFrame
		shell.Velocity = script.Parent.Ejection.CFrame.lookVector * 26 + Vector3.new(0, 5, 0)
		shell.RotVelocity = Vector3.new(-10,40,30)
		shell.CanCollide = false
		shell.Parent = game.Workspace.Shells
	elseif configuration.ShellType == 2 then
		local shell = game.ReplicatedStorage.GunSystem.Shell2:Clone()
		shell.CFrame =  script.Parent.Ejection.CFrame
		shell.Velocity = script.Parent.Ejection.CFrame.lookVector * 26 + Vector3.new(0, 5, 0)
		shell.RotVelocity = Vector3.new(-10,40,30)
		shell.CanCollide = false
		shell.Parent = game.Workspace.Shells
	elseif configuration.ShellType == 3 then
		local shell = game.ReplicatedStorage.GunSystem.Shell3:Clone()
		shell.CFrame =  script.Parent.Ejection.CFrame
		shell.Velocity = script.Parent.Ejection.CFrame.lookVector * 26 + Vector3.new(0, 5, 0)
		shell.RotVelocity = Vector3.new(-10,40,30)
		shell.CanCollide = false
		shell.Parent = game.Workspace.Shells
	end
end

function hitDetection(hit,ray, mousepos)
	local model = hit:FindFirstAncestorOfClass("Model")
	if model then
		local humanoid = model:FindFirstChildWhichIsA("Humanoid") or nil
		if humanoid then
			if hit.Name == "Head" then
				humanoid:TakeDamage(configuration.HeadShotDamage)
			else
				humanoid:TakeDamage(configuration.Damage)
			end
		else
			return true
		end
	end
end

function fire(player,mousePos)
	local bullet = newBullet()
	applyPhysics(bullet,mousePos)
	shellejection()
	
	local rayFilter = rayFilter(player)
	
	local lastPos = bullet.Position
	local range = configuration.MaxRange
	while range > 0 do
		task.wait()

		local rayLength = (lastPos-bullet.Position).Magnitude
		range = range - rayLength
		local rayPos = bullet.Position
		local rayDirection = CFrame.new(lastPos,rayPos).lookVector
		
		--updateTracer(tracer,lastPos,rayPos)

		local ray = workspace:Raycast(lastPos,rayDirection*rayLength,rayFilter) 
		if ray then
			bullet:Destroy()
			local hit = ray.Instance
			rayPos = ray.Position

			--updateTracer(tracer,lastPos,rayPos)
			
			if hitDetection(hit,ray, mousePos) then
				script.Parent.Shot:FireClient(player)
			end
			break
		end
		if bullet.Parent == nil then
			bullet:Destroy()
			break
		end
		lastPos = bullet.Position
	end
	if bullet then
		bullet:Destroy()
	end
end

--elseif material == Enum.Material.Wood or material == Enum.Material.WoodPlanks then
--	local mat = game.ReplicatedStorage.GunSystem.Impact.Wood
--	if mat then
--		local hole = Instance.new("Part", workspace)
--		local particles = mat:FindFirstChildWhichIsA("BasePart")
--		local tab = mat.Sounds:GetChildren()
--		local rs = tab[math.random(1, #tab)]
--		local cl = rs:Clone()
--		cl.Parent = hole
--		cl:Play()

--		hole.Size = Vector3.new(0.7, 0.7, 0.001)
--		hole.Transparency = 1
--		hole.CanCollide = false
--		hole.Position = pos
--		hole.CFrame = CFrame.new(pos,pos+normal)
--		hole.Anchored = true
--		local decal = mat:FindFirstChildOfClass("Decal")
--		if decal then
--			local clone = decal:Clone()
--			clone.Parent = hole
--		end
--		game.Debris:AddItem(hole, 6)
--	end
--end

Settings (Module Script):

local module = {
	----Main
	['WeaponName'] = 'Pistol';
	['ShellType'] = 3; --1 rifle, 2 shotgun, 3 pistol
	['Auto'] = false;
	['Ammo'] = 8; --8 default
	['Mag'] = 8; --8 default
	['Bullets'] = 1; --1 default
	['Spread'] = 1; --1 default
	['BulletVelocity'] = 1000; --1000 default
	['FireRate'] = 0.15; --0.15 default
	['Damage'] = 30; --30 default
	['HeadShotDamage'] = 50; --50 default
	['MaxRange'] = 2000; --2000 default
	['MouseIcon'] = 'http://www.roblox.com/asset/?id=5681283745';
	['ReloadTime'] = 2.1; --2.1 default
	['Recoil'] = 6; --6 default
	['EquipTime'] = 0.5; --0.5 default
	----Mods
	['SafeMode'] = true;
	----Keys
	['ReloadKey'] = Enum.KeyCode.R;
	['SafeModeKey'] = Enum.KeyCode.V;
}

return module

Help Soon,

papahetfan

Well just breezing through your local script, it doesn’t have any functions whatsoever that would make play for Mobile or Xbox players even possible,

I suggest you just use ContextActionService instead of UserInputService since your trying to hit all platforms, CAS makes it super easy to bind a function to mul-tiple different platforms inputs

Check it out!

https://developer.roblox.com/en-us/api-reference/class/ContextActionService

I’m not very good at CAS, I can’t think of where to start and code the script at.