Issue with an AI code

Hi everyone, i’ve tried to use AI for a script that has a UI frame transition (appears from nowhere smoothly) when touching part
Heres the script:

local block = workspace:WaitForChild("Part")


local screenGui = Instance.new("ScreenGui")
screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")


local frame1 = Instance.new("Frame")
frame1.Size = UDim2.new(0, 200, 0, 100)
frame1.Position = UDim2.new(0.5, -100, 0.5, -50)
frame1.BackgroundColor3 = Color3.new(1, 1, 1)
frame1.Parent = screenGui

local frame2 = Instance.new("Frame")
frame2.Size = UDim2.new(0, 200, 0, 100)
frame2.Position = UDim2.new(1, 0, 0, 0)
frame2.BackgroundColor3 = Color3.new(0, 1, 0)
frame2.Parent = screenGui


local function TransitionToScreen2()
frame1:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
frame2:TweenPosition(UDim2.new(0.5, -100, 0.5, -50), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
end

local function OnBlockTouched()
TransitionToScreen2()
end

block.Touched:Connect(OnBlockTouched)

I had to remove documentations cuz they were in Russian.
Heres the video of issue:


Can someone help me so it will work?
Help/Feedback would be appreciated.
P.S: some parts of script i had to change cuz they didn’t work
I used AI because i almost dont know how to script (i know only 30%)

It might be because the actual frames are not showing onscreen, Maybe try making the frame in studio, and tweening it there? instead of creating them via script.
Also, If that doesn’t work, Try moving the position a little bit to know if its just the frame going off screen, or the script not working in general.

(also sick mouse cursor)


I think its still not working, lemme try using BackgroundTransparency.
P.S: i used it and still not working :frowning_face:

This is a client script, Right?
Also, If nothing is working, Try using prints, Like so:




local function TransitionToScreen2()
print("Function called")
--other code
end

local function OnBlockTouched()
TransitionToScreen2()
print("Touched part")
end

block.Touched:Connect(OnBlockTouched)

if its server sided, it wont work at all.


should it be here?


uhhh

roblox touched event moment

Judging by what the output says, You are running the code on a server script, It must be local.

No no, Its fine where it was. Im currently testing smth rn ill come back with results

so i need to move the text of script into localscript?

Yes, Since its calling for the local player, It has to be on a local script, Copy the code, delete the server script, and make a new local script (place it in the part, or in StarterCharacterScripts, StarterCharacterScripts might be better depending on what ur making)

Good news! I’ve figured it out.
Place this script into StarterCharacterScripts

local block = workspace:WaitForChild("Part")


local screenGui = Instance.new("ScreenGui")
screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")


local frame1 = Instance.new("Frame")
frame1.Size = UDim2.new(0, 200, 0, 100)
frame1.Position = UDim2.new(0.5, -100, 0.5, -50)
frame1.BackgroundColor3 = Color3.new(1, 1, 1)
frame1.Parent = screenGui

local frame2 = Instance.new("Frame")
frame2.Size = UDim2.new(0, 200, 0, 100)
frame2.Position = UDim2.new(1, 0, 0, 0)
frame2.BackgroundColor3 = Color3.new(0, 1, 0)
frame2.Parent = screenGui


local function TransitionToScreen2()
	frame1:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
	frame2:TweenPosition(UDim2.new(0.5, -100, 0.5, -50), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
end

local function OnBlockTouched()
	TransitionToScreen2()
end

block.Touched:Connect(OnBlockTouched)

Nothing was wrong with your original code, It was just the placing.

i forgor da symbol thats why aint workin LOL

OH-

I was gonna write a reply asking what line it was lol

can ya help me remove gui from screen when not touching part?
im dum dum at scripting knowledge

when you leave the part? i think you can call :destroy() on the gui when the part’s TouchEnded function has fired.

If you want it to come back when the part is touched, Try this (probably not the best approach, but ya get the idea)

It acts odd, but thats because of the Touched event in roblox being really weird.


local oncooldown = false
local cooldowntime = 1



local function TransitionToScreen2()


	local screenGui = Instance.new("ScreenGui")
	screenGui.Name = "GuiTween"
	screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
	local frame1 = Instance.new("Frame")
	frame1.Size = UDim2.new(0, 200, 0, 100)
	frame1.Position = UDim2.new(0.5, -100, 0.5, -50)
	frame1.BackgroundColor3 = Color3.new(1, 1, 1)
	frame1.Parent = screenGui

	local frame2 = Instance.new("Frame")
	frame2.Size = UDim2.new(0, 200, 0, 100)
	frame2.Position = UDim2.new(1, 0, 0, 0)
	frame2.BackgroundColor3 = Color3.new(0, 1, 0)
	frame2.Parent = screenGui

	frame1:TweenPosition(UDim2.new(-1, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
	frame2:TweenPosition(UDim2.new(0.5, -100, 0.5, -50), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
end

local function OnBlockTouched(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not oncooldown then
		oncooldown = true
		TransitionToScreen2()
		task.wait(cooldowntime)
		oncooldown = false
	end
end
local function OnBlockLeft()
	if game.Players.LocalPlayer:WaitForChild("PlayerGui"):FindFirstChild("GuiTween") then
		game.Players.LocalPlayer:WaitForChild("PlayerGui"):FindFirstChild("GuiTween"):Destroy()
	end
end

block.Touched:Connect(OnBlockTouched)
block.TouchEnded:Connect(OnBlockLeft)

This is only example code, Its early where i am so i can’t really perfect it since im pretty tired


i tried to make transition when TouchEnded LMAO

is the frame supposed to go flying off screen like that?

Also, take a look at my other recent post, i edited it.

It wasnt supposed to go flying

I sure would not rely on AI for anything other than suggestions. There is no substitute to hands on learning and research when it comes to scripting. AI will never be able to conceive concepts like a real programmer can. Sure to send you down a few bad roads …