UI looks terrible and player is unable to collect collectibles in mobile

I wasn’t sure where to post this, because i think the collectibles issue has something to do with my code.
Anyways, so, i tried to play my game in Roblox on the actual website (not Studio), and it seemed to work pretty good. Everything ran fine, i could grab the coins and stuff, the GUI looked nice, etc. However, for mobile, it’s a completely different story. In Studio, when i play with mobile mode, everything works perfectly fine, however when i play on my phone it’s just completely broken. Here is a video for both of the issues :

Client Code :

--||Services
local Players = game:GetService("Players")
local Replicated_Storage = game:GetService("ReplicatedStorage")
--||Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Hum_Root = Character:WaitForChild("HumanoidRootPart")
local Player_Gui = Player.PlayerGui
local Main_GUI = Player_Gui:WaitForChild("Main_GUI")
------------------------------------------------------------------------------
local Events_Folder = Replicated_Storage.FLDR_EVENTS
local Leader_Stats = Player:WaitForChild("leaderstats")
------------------------------------------------------------------------------
local Coins = Main_GUI.Coins
local Coins_Folder = workspace:WaitForChild("Coins")
local Coins_Display = Coins.CoinDisplay
local Coin_Event = Events_Folder.CoinEvent
local Coin_Val = Leader_Stats.Coins
------------------------------------------------------------------------------
local Crystals = Main_GUI.Crystals
local Crystals_Folder = workspace:WaitForChild("Crystals")
local Crystal_Display = Crystals.CrystalDisplay
local Crystal_Event = Events_Folder.CrystalEvent
local Crystal_Val = Leader_Stats.Crystals
------------------------------------------------------------------------------
local IBs_Folder = workspace:WaitForChild("ItemBlocks")
local IB_Event = Events_Folder.ItemBlockEvent
------------------------------------------------------------------------------
--||Function
for __, Coin in pairs(Coins_Folder:GetChildren()) do
	local Sparkles = Coin.Sparkles
	local Light = Coin.PointLight
	local Collect = Coin.Collect
	local function onTouched(Hit)
		if Hit and Hit.Parent:FindFirstChild("Humanoid") then
			local PlayerHit = Players:GetPlayerFromCharacter(Hit.Parent)
			if PlayerHit == nil then
				return
			end
			Coin.CanTouch = false
			Coin_Event:FireServer(Coin_Val, Coin, Sparkles, Light, Collect)
		end
	end
	Coin.Touched:Connect(onTouched)
end
------------------------------------------------------------------------------
for __, Crystal in pairs(Crystals_Folder:GetChildren()) do
	local Green_Sparkles = Crystal.GreenSparkles
	local Green_Glow = Crystal.GreenGlow
	local Light = Crystal.PointLight
	local Glow = Crystal.Glow
	local Collect = Crystal.Collect
	local CSnd = Crystal.CSnd
	local function onTouched(Hit)
		if Hit and Hit.Parent:FindFirstChild("Humanoid") then
			local PlayerHit = Players:GetPlayerFromCharacter(Hit.Parent)
			if PlayerHit == nil then
				return
			end
			Crystal.CanTouch = false
			Crystal_Event:FireServer(Crystal_Val, Crystal, Green_Sparkles, Green_Glow, Light, Glow, Collect, CSnd, Hum_Root)
		end
	end
	Crystal.Touched:Connect(onTouched)
end
------------------------------------------------------------------------------
for __, Block in pairs(IBs_Folder:GetChildren()) do
	local Left = Block:WaitForChild("Left")
	local Right = Block:WaitForChild("Right")
	local Center = Block:WaitForChild("Center")
	local Hitbox = Block:WaitForChild("Hitbox")
	local HitS = Hitbox.HitS
	local Collect = Hitbox.Collect
	local Light = Center.SpotLight
	local Sparkles = Center.Sparkles
	local function onTouched(Hit)
		if Hit and Hit.Parent:FindFirstChild("Humanoid") then
			local PlayerHit = Players:GetPlayerFromCharacter(Hit.Parent)
			if PlayerHit == nil then
				return
			end
			Hitbox.CanTouch = false
			IB_Event:FireServer(Coin_Val, Block, Left, Right, Center, Hitbox, HitS, Collect, Light, Sparkles)
		end
	end
	Hitbox.Touched:Connect(onTouched)
end
------------------------------------------------------------------------------
while true do
	Coins_Display.Text = "x"..Coin_Val.Value
	Crystal_Display.Text = "x"..Crystal_Val.Value
	task.wait()
end
------------------------------------------------------------------------------

Server Code :

--||Services
local Players = game:GetService("Players")
local Replicated_Storage = game:GetService("ReplicatedStorage")
local Tween_Service = game:GetService("TweenService")
--||Variables
local Events_Folder = Replicated_Storage.FLDR_EVENTS
local Coins_Folder = workspace.Coins
local IBs_Folder = workspace.ItemBlocks
local Crystals_Folder = workspace.Crystals
--||Functions
------------------------------------------------------------------------------
local function onPlayerAdded(Player)
	local function onCharacterAdded()
		local Character = Player.Character or Player.CharacterAdded:Wait()
		local Humanoid = Character:WaitForChild("Humanoid")
		local Root = Character:WaitForChild("HumanoidRootPart")
		local LeaderStats = Instance.new("Folder", Player)
		Humanoid.WalkSpeed = 26
		Humanoid.JumpPower = 50
		LeaderStats.Name = "leaderstats"
		------------------------------------------------------------------------------
		local Coins = Instance.new("IntValue")
		Coins.Name = "Coins"
		Coins.Value = 0
		Coins.Parent = LeaderStats
		------------------------------------------------------------------------------
		local Crystals = Instance.new("IntValue")
		Crystals.Name = "Crystals"
		Crystals.Value = 0
		Crystals.Parent = LeaderStats
	end
	Player.CharacterAdded:Connect(onCharacterAdded)
end
------------------------------------------------------------------------------
local function onCoinEvent(Player, Coin_Val, Coin, Sparkles, Light, Collect)
	Coin.CanTouch = false
	Collect:Play()
	Light:Destroy()
	Sparkles.Enabled = true
	Coin.Transparency = 1
	Collect:Play()
	Sparkles:Emit()
	Coin_Val.Value = Coin_Val.Value + 1
	task.wait(0.5)
	Coin:Destroy()
end
------------------------------------------------------------------------------
local function onIBEvent(Player, Coin_Val, Block, Left, Right, Center, Hitbox, HitS, Collect, Light, Sparkles)
	Collect:Play()
	Hitbox.CanTouch = false
	Sparkles.Enabled = true
	Sparkles:Emit()
	Light:Destroy()
	HitS:Play()
	Collect:Play()
	Left:Destroy()
	Right:Destroy()
	Center.BrickColor = BrickColor.new("Dark orange")
	Coin_Val.Value = Coin_Val.Value + 5
	local Block_TInfo = TweenInfo.new(0.25, Enum.EasingStyle.Bounce, Enum.EasingDirection.In)
	local TweenUp = Tween_Service:Create(Center, Block_TInfo, {CFrame = Center.CFrame + Vector3.new(0, 1, 0)})
	local TweenDown = Tween_Service:Create(Center, Block_TInfo, {CFrame = Center.CFrame - Vector3.new(0, 0.5, 0)})
	TweenUp:Play()
	task.wait(0.4)
	Sparkles:Destroy()
	TweenDown:Play()
end
------------------------------------------------------------------------------
local function onCrystalEvent(Player, Crystal_Val, Crystal, Green_Sparkles, Green_Glow, Light, Glow, Collect, CSnd, Root)
	Glow:Stop()
	Collect:Play()
	CSnd:Play()
	Crystal.CanTouch = false
	Crystal.Transparency = 1
	Green_Sparkles:Destroy()
	Green_Glow:Destroy()
	Light:Destroy()
	Crystal_Val.Value = Crystal_Val.Value + 1
	local Green_Explosion = Instance.new("Part", Root)
	Green_Explosion.Size = Vector3.new(.5,.5,.5)
	Green_Explosion.BrickColor = BrickColor.new(0, 255, 0)
	Green_Explosion.Material = Enum.Material.Neon
	Green_Explosion.Shape = Enum.PartType.Ball
	Green_Explosion.Position = Root.Position
	Green_Explosion.Transparency = 0
	Green_Explosion.CanCollide = false
	local Weld = Instance.new("WeldConstraint", Green_Explosion)
	Weld.Part0 = Green_Explosion
	Weld.Part1 = Root
	local Crystal_TI = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
	local TweenGE = Tween_Service:Create(Green_Explosion, Crystal_TI, {Size = Vector3.new(6, 6, 6), Transparency = 1})
	TweenGE:Play()
	task.wait(.5)
	Green_Explosion:Destroy()
end
------------------------------------------------------------------------------
--||Connections
Players.PlayerAdded:Connect(onPlayerAdded)
Events_Folder.CoinEvent.OnServerEvent:Connect(onCoinEvent)
Events_Folder.ItemBlockEvent.OnServerEvent:Connect(onIBEvent)
Events_Folder.CrystalEvent.OnServerEvent:Connect(onCrystalEvent)

image

5 Likes

Do you use any gui object or property that is currently in Beta? Beta features only works in studio.

1 Like

No, at least not that i know of. (Keep in mind this is only happening with the imagelabels.)
image

What plugin are you using to make the studios look smoother?

Are you talking about the Icons for the things in the picture ? I use Vanilla 3.

1 Like

Before you do anything, put in some (warn(),print(),error()). Put in whatever string and debug from there. Check if things are returning as nil or something in your script might have a error.

for __, Coin in pairs(Coins_Folder:GetChildren()) do
	if Coin then
		print("Coin is good.")
	else
		warn("Coin is bad!")
	end
	local Sparkles = Coin.Sparkles
	local Light = Coin.PointLight
	local Collect = Coin.Collect
	local function onTouched(Hit)
		if Hit then
			print("Hit Coin.")
		else
			warn("Coin didn't detect hit!")
		end
		if Hit and Hit.Parent:FindFirstChild("Humanoid") then
			print("Humanoid found for Coin.")
			local Hit_Hum = Hit.Parent:FindFirstChild("Humanoid")
			local PlayerHit = Players:GetPlayerFromCharacter(Hit_Hum.Parent)
			if PlayerHit == nil then
				print("Player not here!")
				return
			end
			print("Player found, Coin event fired to server.")
			Coin.CanTouch = false
			Coin_Event:FireServer(Coin_Val, Coin, Sparkles, Light, Collect)
		end
	end
	Coin.Touched:Connect(onTouched)
end

I put these and they all work. I don’t know why but it seems that now the item collection system works completely fine? Even on mobile.

That’s good, there might have been a problem with the script where it wasnt detecting something i don’t know though. Happy it’s working.

Alright thanks, if it doesn’t work again then i’ll tell you :+1:. Anyways… now there’s still one more issue to fix, and that’s the appearence of the UI on mobile…

Click the frames or whatever form of UI you used and check the size, make sure it’s not like
(0,number,0,number) this is offset and will not look good on other devices. You want it to look like this: (number,0,number0)

If this doesn’t work I don’t know then.

It was already like that (number,0,number0) and it still didn’t work. I tried using scale instead and it didn’t work. Anyways, the collectibles issue happened again! It didn’t print anything in the output tho…

This is a bump. (00000111122222)

the images are most likely caused by the source image you uploaded being very small and roblox is upscaling them but theres not enough pixels to keep its detail

for the collectables, double check that they have CanTouch enabled, follow the code in your head and act like you are running it and see if anything would go wrong, use prints throughout the code to see where it gets cut off

Thanks for the fix for the GUI. I resized the sprites by 400% and now it looks much better. But there’s still the other issue :

--||Services
local Players = game:GetService("Players")
local Replicated_Storage = game:GetService("ReplicatedStorage")
--||Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Player_Gui = Player.PlayerGui
local Main_GUI = Player_Gui:WaitForChild("Main_GUI")
------------------------------------------------------------------------------
local Events_Folder = Replicated_Storage.FLDR_EVENTS
local Leader_Stats = Player:WaitForChild("leaderstats")
------------------------------------------------------------------------------
local Coins = Main_GUI.Coins
local Coins_Folder = workspace:WaitForChild("Coins")
local Coins_Display = Coins.CoinDisplay
local Coin_Event = Events_Folder.CoinEvent
local Coin_Val = Leader_Stats.Coins
------------------------------------------------------------------------------
local Crystals = Main_GUI.Crystals
local Crystals_Folder = workspace:WaitForChild("Crystals")
local Crystal_Display = Crystals.CrystalDisplay
local Crystal_Event = Events_Folder.CrystalEvent
local Crystal_Val = Leader_Stats.Crystals
------------------------------------------------------------------------------
local IBs_Folder = workspace:WaitForChild("ItemBlocks")
local IB_Event = Events_Folder.ItemBlockEvent
--||Function
print("Code works good so far")
for __, Obj in ipairs(Coins_Folder:GetDescendants()) do
	print("Looping through Coins folder")
	if Obj:IsA("UnionOperation") and Obj.Name == "Coin" then
		print("Checked if the coin is a union successfully")
------------------------------------------------------------------------------
		local Collect_SFX = Obj:WaitForChild("CLCT_SND")
		local Light_FX = Obj:WaitForChild("PointLight")
		local Sparkles_FX = Obj:WaitForChild("Sparkles")
------------------------------------------------------------------------------
		Obj.Touched:Connect(function(Hit)
			print("Coin has been touched, don't know if it's the player yet tho.")
			if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
				print("Checked if the toucher's parent is a character.")
------------------------------------------------------------------------------
				local Player_Hit = Players:GetPlayerFromCharacter(Hit.Parent)
------------------------------------------------------------------------------
				if Player_Hit then
					print("Obtained the Player from the toucher successfully!")
					Obj.CanTouch = false
					local Leader_Stats = Player_Hit:WaitForChild("leaderstats")
					local Plr_Coin_Val = Leader_Stats.Coins
					Coin_Event:FireServer(Plr_Coin_Val, Obj, Sparkles_FX, Light_FX, Collect_SFX)
				end
------------------------------------------------------------------------------
			end
		end)
	end
end
------------------------------------------------------------------------------
for __, Obj in ipairs(Crystals_Folder:GetDescendants()) do
	if Obj:IsA("Part") or Obj:IsA("BasePart") and Obj.Name == "Crystal" then
------------------------------------------------------------------------------
		local Collect_SFX = Obj:WaitForChild("CLCT_SND")
		local Glow_SFX = Obj:WaitForChild("GLOW_SND")
		local Effect_SFX = Obj:WaitForChild("FX_SND")
		local Light_FX = Obj:WaitForChild("PointLight")
		local Sparkles_FX = Obj:WaitForChild("GreenSparkles")
		local Glow_FX = Obj:WaitForChild("GreenGlow")
------------------------------------------------------------------------------
		Obj.Touched:Connect(function(Hit)
			if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
------------------------------------------------------------------------------
				local Player_Hit = Players:GetPlayerFromCharacter(Hit.Parent)
------------------------------------------------------------------------------
				if Player_Hit then
					Obj.CanTouch = false
					local Hum_Root = Hit.Parent:WaitForChild("HumanoidRootPart")
					local Leader_Stats = Player_Hit:WaitForChild("leaderstats")
					local Plr_Crystal_Val = Leader_Stats.Crystals
					Crystal_Event:FireServer(Plr_Crystal_Val, Obj, Sparkles_FX, Glow_FX, Light_FX, Glow_SFX, Collect_SFX, Effect_SFX, Hum_Root)
				end
------------------------------------------------------------------------------
			end
		end)
	end
end
------------------------------------------------------------------------------
for __, Obj in ipairs(IBs_Folder:GetDescendants()) do
	if Obj:IsA("Model") and Obj.Name == "ItemBlock" then
------------------------------------------------------------------------------
		local Left = Obj:WaitForChild("Left")
		local Right = Obj:WaitForChild("Right")
		local Center = Obj:WaitForChild("Center")
		local Hitbox = Obj:WaitForChild("Hitbox")
		local Hit_SFX = Hitbox.HIT_SND
		local Collect_SFX = Hitbox.CLCT_SND
		local Light_FX = Center.SpotLight
		local Sparkles_FX = Center.Sparkles
------------------------------------------------------------------------------
		Hitbox.Touched:Connect(function(Hit)
			if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
------------------------------------------------------------------------------
				local Player_Hit = Players:GetPlayerFromCharacter(Hit.Parent)
------------------------------------------------------------------------------
				if Player_Hit then
					Hitbox.CanTouch = false
					local Hum_Root = Hit.Parent:WaitForChild("HumanoidRootPart")
					local Leader_Stats = Player_Hit:WaitForChild("leaderstats")
					local Plr_Coin_Val = Leader_Stats.Coins
					IB_Event:FireServer(Plr_Coin_Val, Obj, Left, Right, Center, Hitbox, Hit_SFX, Collect_SFX, Light_FX, Sparkles_FX)
				end
------------------------------------------------------------------------------
			end
		end)
	end
end
------------------------------------------------------------------------------
while true do
	Coins_Display.Text = "x"..Coin_Val.Value
	Crystal_Display.Text = "x"..Crystal_Val.Value
	task.wait()
end
------------------------------------------------------------------------------

I rewrote the code. Anyways, i put the print statements and when i can’t collect the coins, it doesn’t print anything past print("Code works good so far")

that means theres nothing in the coins folder

this could be caused by a few situations

  1. theres literally nothing in it
  2. this script is running before anything gets added to the folder
  3. this script is running before the coins are loaded in (this usually happens with local scripts if the scripts runs as soon as the player joins)

So then how would i go about waiting until the coins are loaded in the folder, since there are indeed coins in it.

take everything that is in the loop and put it into a function

then call the function in that loop
and finally connect to the ChildAdded or DescendantAdded of the folder and call the function

Like this right?

repeat 
	task.wait()
 until game:IsLoaded()
--||Services
local Players = game:GetService("Players")
local Replicated_Storage = game:GetService("ReplicatedStorage")
--||Variables
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Player_Gui = Player.PlayerGui
local Main_GUI = Player_Gui:WaitForChild("Main_GUI")
------------------------------------------------------------------------------
local Events_Folder = Replicated_Storage.FLDR_EVENTS
local Leader_Stats = Player:WaitForChild("leaderstats")
------------------------------------------------------------------------------
local Coins = Main_GUI.Coins
local Coins_Folder = workspace:WaitForChild("Coins")
local Coins_Display = Coins.CoinDisplay
local Coin_Event = Events_Folder.CoinEvent
local Coin_Val = Leader_Stats.Coins 
------------------------------------------------------------------------------
local Crystals = Main_GUI.Crystals
local Crystals_Folder = workspace:WaitForChild("Crystals")
local Crystal_Display = Crystals.CrystalDisplay
local Crystal_Event = Events_Folder.CrystalEvent
local Crystal_Val = Leader_Stats.Crystals
------------------------------------------------------------------------------
local IBs_Folder = workspace:WaitForChild("ItemBlocks")
local IB_Event = Events_Folder.ItemBlockEvent
--||Function
function Coin_Function(Var)
	if Var:IsA("UnionOperation") and Var.Name == "Coin" then
------------------------------------------------------------------------------
		local Collect_SFX = Var:WaitForChild("CLCT_SND")
		local Light_FX = Var:WaitForChild("PointLight")
		local Sparkles_FX = Var:WaitForChild("Sparkles")
------------------------------------------------------------------------------
		Var.Touched:Connect(function(Hit)
			if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
------------------------------------------------------------------------------
				local Player_Hit = Players:GetPlayerFromCharacter(Hit.Parent)
------------------------------------------------------------------------------
				if Player_Hit then
					Var.CanTouch = false
					local Leader_Stats = Player_Hit:WaitForChild("leaderstats")
					local Plr_Coin_Val = Leader_Stats.Coins
					Coin_Event:FireServer(Plr_Coin_Val, Var, Sparkles_FX, Light_FX, Collect_SFX)
				end
------------------------------------------------------------------------------
			end
		end)
	end
end
------------------------------------------------------------------------------
for __, Obj in ipairs(Coins_Folder:GetDescendants()) do
	Coins_Folder.DescendantAdded:Connect(Coin_Function(Obj))
end
------------------------------------------------------------------------------
function Crystal_Function(Var)
	if Var:IsA("Part") or Var:IsA("BasePart") and Var.Name == "Crystal" then
------------------------------------------------------------------------------
		local Collect_SFX = Var:WaitForChild("CLCT_SND")
		local Glow_SFX = Var:WaitForChild("GLOW_SND")
		local Effect_SFX = Var:WaitForChild("FX_SND")
		local Light_FX = Var:WaitForChild("PointLight")
		local Sparkles_FX = Var:WaitForChild("GreenSparkles")
		local Glow_FX = Var:WaitForChild("GreenGlow")
		------------------------------------------------------------------------------
		Var.Touched:Connect(function(Hit)
			if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
------------------------------------------------------------------------------
				local Player_Hit = Players:GetPlayerFromCharacter(Hit.Parent)
------------------------------------------------------------------------------
				if Player_Hit then
					Var.CanTouch = false
					local Hum_Root = Hit.Parent:WaitForChild("HumanoidRootPart")
					local Leader_Stats = Player_Hit:WaitForChild("leaderstats")
					local Plr_Crystal_Val = Leader_Stats.Crystals
					Crystal_Event:FireServer(Plr_Crystal_Val, Var, Sparkles_FX, Glow_FX, Light_FX, Glow_SFX, Collect_SFX, Effect_SFX, Hum_Root)
				end
------------------------------------------------------------------------------
			end
		end)
	end
end
------------------------------------------------------------------------------
for __, Obj in ipairs(Crystals_Folder:GetDescendants()) do
	Coins_Folder.DescendantAdded:Connect(Crystal_Function(Obj))
end
------------------------------------------------------------------------------
function IB_Function(Var)
	if Var:IsA("Model") and Var.Name == "ItemBlock" then
------------------------------------------------------------------------------
		local Left = Var:WaitForChild("Left")
		local Right = Var:WaitForChild("Right")
		local Center = Var:WaitForChild("Center")
		local Hitbox = Var:WaitForChild("Hitbox")
		local Hit_SFX = Hitbox.HIT_SND
		local Collect_SFX = Hitbox.CLCT_SND
		local Light_FX = Center.SpotLight
		local Sparkles_FX = Center.Sparkles
------------------------------------------------------------------------------
		Hitbox.Touched:Connect(function(Hit)
			if Hit.Parent:IsA("Model") and Hit.Parent:FindFirstChild("Humanoid") then
------------------------------------------------------------------------------
				local Player_Hit = Players:GetPlayerFromCharacter(Hit.Parent)
------------------------------------------------------------------------------
				if Player_Hit then
					Hitbox.CanTouch = false
					local Hum_Root = Hit.Parent:WaitForChild("HumanoidRootPart")
					local Leader_Stats = Player_Hit:WaitForChild("leaderstats")
					local Plr_Coin_Val = Leader_Stats.Coins
					IB_Event:FireServer(Plr_Coin_Val, Var, Left, Right, Center, Hitbox, Hit_SFX, Collect_SFX, Light_FX, Sparkles_FX)
				end
------------------------------------------------------------------------------
			end
		end)
	end
end
------------------------------------------------------------------------------
for __, Obj in ipairs(IBs_Folder:GetDescendants()) do
	Coins_Folder.DescendantAdded:Connect(IB_Function(Obj))
end
------------------------------------------------------------------------------
while true do
	Coins_Display.Text = "x"..Coin_Val.Value
	Crystal_Display.Text = "x"..Crystal_Val.Value
	task.wait()
end
------------------------------------------------------------------------------

no for the loop, just call the function
then after the loop connect to DescendantAdded

So like this?

for __, Obj in ipairs(IBs_Folder:GetDescendants()) do
	IB_Function(Obj)
end
--||Connections
IBs_Folder.DescendantAdded:Connect(IB_Function())