For some reason, I can't get my gear to work on mobile even though it works perfectly on PC. I've been trying to get it to work but nothing works for me!?

Serverscript in Tool



		local Tool = script.Parent
		local Remote = Tool:WaitForChild("Remote")
		local Handle = Tool:WaitForChild("Handle")
		
		local Conf = script.Parent.Conf
		
		local BrokenEggMesh = "http://www.roblox.com/asset/?id=1529081"
		
		local FriendlyFire = false
		
		local CanThrow = true
		
		local AttackPower = 1
		local AttackDamage = Conf.Damage.Value
		local HeadShot = Conf.Headshot.Value
		local AtackRechargeTime = 2
		local AttackRecharge = 1/AtackRechargeTime
		local AttackSpeed = 256
		
		local Equipped = false
		local Heartbeat = game:GetService("RunService").Heartbeat
		
		local Knives = {}
		
		--returns the wielding player of this tool
		local function getPlayer()
			local char = Tool.Parent
			return game:GetService("Players"):GetPlayerFromCharacter(char)
		end
		
		--helpfully checks a table for a specific value
		local function contains(t, v)
			for _, val in pairs(t) do
				if val == v then
					return true
				end
			end
			return false
		end
		
		--tags a human for the ROBLOX KO system
		local function tagHuman(human)
			local tag = Instance.new("ObjectValue")
			tag.Value = getPlayer()
			tag.Name = "creator"
			tag.Parent = human
			game:GetService("Debris"):AddItem(tag)
		end
		
		--used by checkTeams
		local function sameTeam(otherHuman)
			local player = getPlayer()
			local otherPlayer = game:GetService("Players"):GetPlayerFromCharacter(otherHuman.Parent)
			if player and otherPlayer then
				return player.TeamColor == otherPlayer.TeamColor
			end
			return false
		end
		
		--use this to determine if you want this human to be harmed or not, returns boolean
		local function checkTeams(otherHuman)
			return not (sameTeam(otherHuman) and not FriendlyFire)
		end
		
		local function Morph(player, model)
			local Char = model:Clone()
			local Pos = player.Character:GetPrimaryPartCFrame()
			local Schar = game.StarterPlayer:FindFirstChild("StarterCharacter")
			game:GetService("StarterPlayer")
			player.Character:Destroy()
			player.Character = Char
			Char.Parent = workspace
			Char:SetPrimaryPartCFrame(Pos)
		end
		
		local function getKnife()
			local knife = Handle:clone()
			knife.Trail.Enabled = true
			knife.Transparency = 0
			knife.Hit.Pitch = math.random(90, 110)/100
			
			local lift = Instance.new("BodyForce")
			lift.force = Vector3.new(0, 196.2, 0) * knife:GetMass() * 0.8
			lift.Parent = knife
			
			local proj = Tool.Projectile:Clone()
			proj.Disabled = false
			proj.Parent = knife
			
			return knife
		end
		
		local function equippedLoop()
			while Equipped do
				local dt = Heartbeat:wait()
				
				if AttackPower < 1 then
					AttackPower = AttackPower + dt * AttackRecharge
					if AttackPower > 1 then
						AttackPower = 1
					end 
				end
				
				Handle.Transparency = 1 - AttackPower
			end
		end
		
		local function onLeftDown(mousePos)
			local knife = getKnife()
			knife.CFrame = CFrame.new(Handle.Position, mousePos)
			knife.Velocity = knife.CFrame.lookVector * AttackSpeed * AttackPower
			local damage = AttackDamage * AttackPower
			local touched
			

			touched = knife.Touched:connect(function(hit)
				
				if hit:IsDescendantOf(Tool.Parent) then return end
				if contains(Knives, hit) then return end
				
				if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
					
					knife.Trail.Enabled = false
					
					local human = hit.Parent.Humanoid
					
						tagHuman(human)
						human:TakeDamage(damage)
						knife.Hit:Play()
						
						knife.Transparency = 1
						
				else
					
					knife.Trail.Enabled = false	
					
				end
		
				knife.Projectile:Destroy()

				
				
				local w = Instance.new("Weld")
				w.Part0 = hit
				w.Part1 = knife
				w.C0 = hit.CFrame:toObjectSpace(knife.CFrame)
				w.Parent = w.Part0
				
				touched:disconnect()
				
				
			end)
			table.insert(Knives, knife)
			knife.Parent = workspace
			
			game:GetService("Debris"):AddItem(knife, 3.5)
			delay(1, function()
				knife.Transparency = 1
			end)
			
			Remote:FireClient(getPlayer(), "PlayAnimation", "Throw")	
			
			Handle.Throw.Pitch = 0.8 + 0.4 * AttackPower
			Handle.Throw:Play()
			
			AttackPower = 0
			
		end
		
		local function onRemote(player, func, ...)
			if player ~= getPlayer() then return end
			
			if func == "LeftDown" or func == "Activated" and CanThrow == true then
				CanThrow = false
				onLeftDown(...)
				wait(1)
				CanThrow = true
			end
		end
		
		local function onEquip()
			Equipped = true
			equippedLoop()
		end
		
		local function onUnequip()
			Equipped = false
		end
		
		
		Remote.OnServerEvent:connect(onRemote)
		Tool.Equipped:connect(onEquip)
		Tool.Unequipped:connect(onUnequip)


Local Script

local Player = game:GetService("Players").LocalPlayer
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
local Tool = script.Parent
local Remote = Tool:WaitForChild("Remote")
local Tracks = {}
local InputType = Enum.UserInputType

local Name = script.Parent.Values.Name.Value

local GiveValue = script.Parent.Values.GiveValue.Value

local BeganConnection, EndedConnection

function playAnimation(animName, ...)
	if Tracks[animName] then
		Tracks[animName]:Play()
	else
		local anim = Tool:FindFirstChild(animName)
		if anim and Tool.Parent and Tool.Parent:FindFirstChild("Humanoid") then
			Tracks[animName] = Tool.Parent.Humanoid:LoadAnimation(anim)
			playAnimation(animName, ...)
		end
	end
end

function stopAnimation(animName)
	if Tracks[animName] then
		Tracks[animName]:Stop()
	end
end

function inputBegan(input)
	if input.UserInputType == InputType.MouseButton1 then
		Remote:FireServer("LeftDown", Mouse.Hit.p)
	end
end

function inputEnded(input)
	if input.UserInputType == InputType.MouseButton1 then
		Remote:FireServer("LeftUp")
	end
end

function onRemote(func, ...)
	if func == "PlayAnimation" then
		playAnimation(...)
		game.ReplicatedStorage.Events.GiveEgg:FireServer(Name,GiveValue)
		print("Fired")
	elseif func == "StopAnimation" then
		stopAnimation(...)
	end
end

function onEquip()
	BeganConnection = UIS.InputBegan:connect(inputBegan)
	EndedConnection = UIS.InputEnded:connect(inputEnded)
end

function onUnequip()
	if BeganConnection then
		BeganConnection:disconnect()
		BeganConnection = nil
	end
	
	if EndedConnection then
		EndedConnection:disconnect()
		EndedConnection = nil
	end
end

Tool.Equipped:connect(onEquip)
Tool.Unequipped:connect(onUnequip)
Remote.OnClientEvent:connect(onRemote)

1 comment

0

Help