Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing Frame gui size when detected mobile or computer. Please help!!!??

So Here is what I have so far

local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled
   and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then

  
	else
	 game.Players.LocalPlayer.PlayerGui.TopGuis.Group.Size.Value = UDim2.new({0.293, 0},{0.122, 0})
	

end

I tested it out on many devices it didn't change a thing. I tested in to local scripts and normal and still nothing. In the output if I put in a regular script it shows an error message on the line about game.Players.LocalPlayers......... and says like attempt to index player gui a nil value. On a local script nothing shows up in the output. Help would be appreciated. My goal here is to change something if detected on a computer. I made the loop to detect for a mobile device and put an else to show when it returns it would be a computer which was my goal to change it. i will change the action it will do but any help will be greatly appreciated.

EDIT: so here is what I have now

local UserInputService = game:GetService("UserInputService")
local label = script.Parent --change to the text label
local frame = script.Parent.Parent
local messages = {
    TouchEnabled = "Tap!",
    KeyboardEnabled = "E",
    GamepadEnabled = "B" --or whatever it is
}


for key, value in pairs(messages) do
    if(UserInputService[key]) then
        label.Text = value
        break
    end
end



local sizing  = {
    TouchEnabled = UDim2.new(0, 0,0, 0)
};

for key, value in pairs(sizing) do
    if(UserInputService[key]) then
        frame.Size= value
        break
    end
end

I was originally editing the text for a button but needed to adjust the size of a whole frame as well so the parent.Parent is the frame

3 comments

0

If you're using the Scaling portion on the X and Y Values, you should be fine, as that size will scale with the device's size. (X Scale, X Offset, Y Scale Y Offset), This is why I prefer to use Scale over Offset as it scales with all devices.

0

You should not need to detect either

0

I am using only size but whenever I scale is to a size for pc I check on mobile the size is ok but the text for a button shrinks as it is text scaled I also need help because on mobile it needs to say tap on pc it should say e but I don't get the detection and the change process yet this gui size change is an experiment I will change that part later but I still need the starting base

1 answer

✓ Accepted answer

well just put a local script in the GUI that you want text changed, and write the following;

local UserInputService = game:GetService("UserInputService")
local label = script.Parent --change to the text label

local messages = {
	TouchEnabled = "Tap",
	KeyboardEnabled = "E",
	GamepadEnabled = "B" --or whatever it is
}


for key, value in pairs(messages) do
	if(UserInputService[key]) then
		label.Text = value
		break
	end
end

also,all you need to do to make things resize and position proportionally on all devices is, make sure the their Size and Position properties are set in Scale and not Offset..

EDIT: you can make specific adjustments to sizing on different devices like this:

local sizing  = {
	TouchEnabled = UDim2.new(S, O, S,O)
};

for key, value in pairs(sizing) do
	if(UserInputService[key]) then
		label.Size= value
		break
	end
end

remember, UDim2 takes 4 numbers, not 2 arrays

3 comments

0

I have a few questions with this what is line 12 doing because I see your for loop is addressing the table which adresses and assigns a variable string for each type of input service but what does the if loop on line 12 do especially the key and also regarding the size and position I did only use size since the beginning and it works pretty much perfect except on computer it looks a little big whi

0

doing Object[propertyName] is equivalent to doing Object.PorpetyName.. therefore, b/c the for loop goes through the table, getting the name of each key, and the value associated with it, it allows us to do UserInputService[key]

0

ahh I forgot about how people use different things for the index and value (i,v) you used key and value

This discussion is preserved as it was. New answers, comments, and votes are closed.