How To Script a Selection Of Mobile And PC UI

You can write your topic however you want, but you need to answer these questions:

  1. I’m trying to achieve a selection of mobile and pc

  2. The issue with this is every time the player dies. The selection doesn’t go and to where it’s use to
    be, It just resets everything starting from square one meaning they have to select if they are on pc or mobile you would think to make a datastore but the problem with this is I want to allow the player to choose every time they join the game NOT when they reset or die therefore to say (NOTE: I do know about the plugin, but to provide the best experience for the game we made two different ui’s)

  3. What I’m thinking of a solution is 1.Clone the ui and destroy the new one given (Issue:My game is gonna do a lot with ui’s therefore i can’t exactly just clone it to the player) 2. Some how pass a value change and another code check’s for that value change and destroy the other ui’s(Issue: Isn’t it gonna change the value every time I respawn)

local Tweenservice = game:GetService("TweenService")

local ScreenMobile = script.Parent.Parent.Parent.MainGuiMobile
local Effect = script.Parent.Parent.Parent.Effects.DarkEffect
local ScreenPC = script.Parent.Parent.Parent.MainGuiPC
local Select = script.Parent.Parent.Parent.Select


local Enter = workspace.Game.Sounds.UISounds.Buttons.Enter
local Leave = Enter.Parent.Leave
local Click = Enter.Parent.Click


local FadeIn = {BackgroundTransparency = 0.5}
local FadeOut = {BackgroundTransparency = 0.9}

local FadeEffect = Tweenservice:Create(Effect,TweenInfo.new(10,Enum.EasingStyle.Sine),{BackgroundTransparency = 1})

function TweenTransparency(...)
	local Args = {...}
	Tweenservice:Create(Args[1],TweenInfo.new(0.75,Enum.EasingStyle.Sine),Args[2]):Play()
	
end


for _, button in pairs(script.Parent.Parent.Frame:GetDescendants()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			if button.Name == "PC" then
				Select.Enabled = false
				FadeEffect:Play()
				ScreenPC.Enabled = true
			elseif button.Name == "Mobile" then
				Select.Enabled = false
				FadeEffect:Play()
				ScreenMobile.Enabled = true
			end
		end)

		button.MouseEnter:Connect(function()
			if button.Name == "PC" then
				TweenTransparency(button,FadeIn)
			elseif button.Name == "Mobile" then
				TweenTransparency(button,FadeIn)
			end
		end)

		button.MouseLeave:Connect(function()
			if button.Name == "PC" then
				TweenTransparency(button,FadeOut)
			elseif button.Name == "Mobile" then
				TweenTransparency(button,FadeOut)
			end
		end)
	end
end

here

2 Likes

Make sure ResetOnSpawn is not enabled.

2 Likes

What about the UI showing up again?

2 Likes

Can you send the script? We can make modifications! :+1:

2 Likes

The script is Provide above And i select resetonspawn is not enabled too it still resets at spawn

1 Like

Basically, when a player picks a device and they die, the device selection menu pops up, right?

1 Like

https://gyazo.com/4583f033d8af5441104175ab4831490b
Correct

1 Like

Alright, where is the script above located? :thinking:

1 Like
game.Players.PlayerAdded:Connect(function(Player)
    script.Gui:Clone().Parent = Player:WaitForChild("PlayerGui")
end)
2 Likes

https://gyazo.com/b813ae10bbb8c63234df1697f7416aaf
It’s located in select Ui Frame In functions

2 Likes

Cloning is a issue My game will do alot with ui’s what if the player resets…

2 Likes

nothing will happen when the player resets? It is on Join so they only get it once when they first enter the game, then when they click either PC or Mobile, have the gui destroy itself

and if you only show this menu once per join, you maybe want a “Confirm” button

2 Likes

Then how will the game know what the player chose. The only solution is once the player chose a device, the game marks the player as that device. Then if the player dies and the game detects that the player chose a device, it will destroy the UIs and clone the UIs that the player chose.

2 Likes

Remote Event To Server → Server sets Player.UserId as the key in a dictionary with the value being either mobile or pc

the value can also be saved locally in a bool value or something in the player obj

3 Likes

Yup. That’s how you do it. :+1:

2 Likes

Yes That would be great i’m a bit new to dictionary’s i’ve done remote events before but not enough
That would be a huge help!

1 Like

Yeah alright, so… the dictionary will be stored like this:

local ChosenDevices = {
    [124780243] = "mobile",
    [345738257] = "pc"
}
3 Likes

Make a server script with this:

game.Players.PlayerAdded:Connect(function(player)
    if not ChosenDevices[player.UserId] then
         return
    end

    if ChosenDevices[player.UserId] == "mobile" then
        --Load mobile UI
    elseif ChosenDevices[player.UserId] == "pc" then
        --Load PC UI
    end
end)
1 Like

for _, button in pairs(script.Parent.Parent.LeftMiddlePC:GetDescendants()) do
for _, button in pairs(script.Parent.Parent.LeftMiddlePhone:GetDescendants()) do
local Inventoryname = script.Parent.Parent.LeftMiddlePhone.InventoryName
local Inventoryname = script.Parent.Parent.LeftMiddlePC.InventoryName

Okay So those are the two things That change for mobile or pc nothing more How do i change variable or the for loop Depending on the choice they choose?

1 Like

Well, maybe you can use BoolValue instead.

3 Likes