Is There A Way To Make This Script Mobile Friendly?

Hello, I have this script here from a grab system and it works fine on a PC but when I test it out on a mobile device it doesn’t work well. So would there be a way to make this script mobile-friendly?

Here is the script:

> local Players    = game:GetService("Players")
> local RunService = game:GetService("RunService")
> local network    = script.Parent.Network
> 
> local character        = script:FindFirstAncestorWhichIsA("Model")
> local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
> local humanoid         = character:WaitForChild("Humanoid")
> local player           = Players:GetPlayerFromCharacter(character)
> local currentObject    = nil
> 
> local range = script.Parent.Range.Value
> 
> function canSetNetworkOwnership(part)
> 	if part.Anchored then 
> 		return false 
> 	end
> 	local model = part:FindFirstAncestorWhichIsA("Model")
> 	if model and model:FindFirstChildWhichIsA("Humanoid") then
> 		return false
> 	end
> 	return part:IsDescendantOf(workspace)
> end
> 
> function isWithinRange(object)
> 	return (object.Position - humanoidRootPart.Position).Magnitude < (range * 1.25 + 5)	
> end
> 
> local conn = network.OnServerEvent:Connect(function(firer, object)
> 	if firer == player then
> 		if currentObject then
> 			currentObject:SetNetworkOwnershipAuto()
> 		end
> 		currentObject = nil
> 		
> 		if object and object:IsA("BasePart") and isWithinRange(object) and canSetNetworkOwnership(object) then
> 			currentObject = object
> 			currentObject:SetNetworkOwner(player)
> 		end
> 	end
> end)
> 
> local dstCheck = RunService.Heartbeat:Connect(function()
> 	if currentObject and ((not isWithinRange(currentObject)) or (not currentObject:IsDescendantOf(workspace))) then
> 		currentObject:SetNetworkOwnershipAuto()
> 		currentObject = nil
> 	end
> end)
> 
> humanoid.Died:Connect(function()
> 	conn:Disconnect()
> 	dstCheck:Disconnect()
> 	if currentObject then
> 		currentObject:SetNetworkOwnershipAuto()
> 	end
> end)

Thanks for your help!

1 Like

I don’t see why this wouldn’t mobile-friendly. Perhaps you are talking about running it on the client through a LocalScript?