How to make a smartphone function?

  1. What do you want to achieve? Keep it simple and clear!

So basically I want to make a smartphone that functions so when you click on an image then Spawn button it will create that object infront of the player and closes the smartphone

  1. What is the issue? Include screenshots / videos if possible!

there is no errors in the output, I tried to figure out coding em myself but end up being stuck that’s why I came here for help

local UIS = game:GetService("UserInputService")
local Smartphone = script.Parent:WaitForChild("Smartphone")
local Block = script.Parent.Smartphone:WaitForChild("Block")
local Cycliner = script.Parent.Smartphone:WaitForChild("Cyclinder")
local Sphre = script.Parent.Smartphone:WaitForChild("Sphre")
local ConfirmationButton = script.Parent.Smartphone:WaitForChild("Spawn")
local PowerOffButt = script.Parent.Smartphone:WaitForChild("PowerOffButt")

UIS.InputBegan:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.P then
		if Smartphone.Visible == false then
			Smartphone.Visible = true
			
			PowerOffButt.MouseButton1Click:Connect(function()
				Smartphone.Visible = false
			end)
			Block.MouseButton1Click:Connect(function()
				
				Cycliner.MouseButton1Click:Connect(function()
					
					Sphre.MouseButton1Click:Connect(function()
						
					end)
				end)
			end)
		end
	end
	ConfirmationButton.MouseButton1Click:Connect(function()
		
	end)
end)

local function CreateObject()
end
CreateObject()

I am a beginner scripter so if you could explain to me so I would understand it instead of copy & paste. I would really appreciate! :heart: :slight_smile:

Instead of adding lots of mousebutton1click events create a variable which updates whenever a button is clicked (you can use a for loop to get all the mousebutton1click events) and when that variable has the specific object type, then you can proceed to create that object within the given function. To spawn the part you can simply just set the CFrame property of the part to the players root CFrame with a bit of Offset

Example:

local Part = --- Part 
local Root = -- Player's Root 

Part.CFrame = Root.CFrame * CFrame.new(0,0,5) -- Infront of the player by 5 studs
1 Like
Code
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Smartphone = script.Parent:WaitForChild("Smartphone")
local Block = Smartphone:WaitForChild("Block")
local Cylinder = Smartphone:WaitForChild("Cylinder")
local Sphere = Smartphone:WaitForChild("Sphere")
local ConfirmationButton = Smartphone:WaitForChild("Spawn")
local PowerOffButt = Smartphone:WaitForChild("PowerOffButt")

local Distance = 5
local CurrentPartType = ""

Block.MouseButton1Click:Connect(function()
    CurrentPartType = "Block"
end)

Cylinder.MouseButton1Click:Connect(function()
    CurrentPartType = "Cylinder"
end)

Sphere.MouseButton1Click:Connect(function()
    CurrentPartType = "Ball"
end)

UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.P then
        Smartphone.Visible = true
    end
end)

PowerOffButt.MouseButton1Click:Connect(function()
    Smartphone.Visible = false
    CurrentPartType = ""
end)

ConfirmationButton.MouseButton1Click:Connect(function()
    Smartphone.Visible = false

    if CurrentPartType ~= "" then
        local Character = Player.Character or Player.CharacterAdded:Wait()
        local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
        local Part = Instance.new("Part")

        Part.PartType = CurrentPartType
        Part.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, Distance)
        Part.Parent = workspace
    end

    CurrentPartType = ""
end)

couple of things I want to say about this code, the Distance property is how far away the part is from you

local Cylinder = Smartphone:WaitForChild("Cylinder")
local Sphere = Smartphone:WaitForChild("Sphere")

I corrected the grammar here so it won’t work unless you change the name in explorer
also I assume this is a local script so I used LocalPlayer

1 Like

I got an error in the output saying PartType is not a valid member of Part. But I fixed it. Anyways your script works tysm, I really appreciate your help! :smiley:

I shall mark it as a solution so others know this topic has been resolved :slight_smile:

1 Like