So I have this button (in a screengui) that if you click it, it will open a frame (in another screengui, not the same one) but I feel lost and I keep getting these errors I don’t know how to fix.
Picture to explain:
The “CodesButton” inside the screengui “Main” is the button where if I click it, the “Frame” should appear, which is found inside “CodesGui”.
Here is the localscript inside “CodesGui”:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local CodesFunction = ReplicatedStorage.CodesFunction
local Frame = script.Parent.Frame
local Redeem = script.Parent.Frame.Redeem
local TextBox = script.Parent.Frame.TextBox
local IsOpen = false
local player = game.Players.LocalPlayer
local CurrentTween = nil
script.Parent.MouseButton1Click:Connect(function()
if CurrentTween then
CurrentTween:Canel()
CurrentTween = nil
end
local Tween = TweenService:Create(Frame, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {
Position = (IsOpen and UDim2.new(0.5, 0, 1.5, 0) or UDim2.new(0.5, 0, 0.5, 0))
})
CurrentTween = Tween
Tween:Play()
IsOpen = not IsOpen
end)
Redeem.MouseButton1Click:Connect(function() -- On Mouse click on the redeem button
local Result = CodesFunction:InvokeServer(TextBox.Text) -- Invokes the server, sends the code that the player has put in the TextBox
if Result == 3 then
TextBox.PlaceholderText = "Code successfully redeemed!"
elseif Result == 2 then
TextBox.PlaceholderText = "Code expired!"
elseif Result == 1 then
TextBox.PlaceholderText = "Code invalid/ already redeemed!"
end
TextBox.Text = ""
wait(2)
TextBox.PlaceholderText = "Enter code here..."
end)
It keeps giving me this error:
And here is the localscript inside “CodesButton”, if it helps:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
player.PlayerGui.CodesGui.Frame.Visible = not player.PlayerGui.CodesGui.Frame.Visible
end)
Please explain thoroughly as I feel like I don’t understand much of whats going on…
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CodesButton = script.Parent
local TweenService = game:GetService("TweenService")
local CodesFunction = ReplicatedStorage:WaitForChild("CodesFunction")
local Frame = script.Parent:WaitForChild("Frame")
local Redeem = Frame:WaitForChild("Redeem")
local TextBox = Frame:WaitForChild("TextBox")
local IsOpen = false
local player = game.Players.LocalPlayer
local CurrentTween = nil
CodesButton.MouseButton1Click:Connect(function()
if CurrentTween then
CurrentTween:Canel()
CurrentTween = nil
end
local Tween = TweenService:Create(Frame, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {
Position = (IsOpen and UDim2.new(0.5, 0, 1.5, 0) or UDim2.new(0.5, 0, 0.5, 0))
})
CurrentTween = Tween
Tween:Play()
IsOpen = not IsOpen
end)
Redeem.MouseButton1Click:Connect(function() -- On Mouse click on the redeem button
local Result = CodesFunction:InvokeServer(TextBox.Text) -- Invokes the server, sends the code that the player has put in the TextBox
if Result == 3 then
TextBox.PlaceholderText = "Code successfully redeemed!"
elseif Result == 2 then
TextBox.PlaceholderText = "Code expired!"
elseif Result == 1 then
TextBox.PlaceholderText = "Code invalid/ already redeemed!"
end
TextBox.Text = ""
wait(2)
TextBox.PlaceholderText = "Enter code here..."
end)
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local LPlayer = Players.LocalPlayer
local PlayerGUI = LPlayer:WaitForChild("PlayerGui")
local Main = PlayerGUI:WaitForChild("Main")
local CodesGUI = PlayerGUI:WaitForChild("CodesGui")
local Bar = Main:WaitForChild("Bar")
local CodesButton = Bar:WaitForChild("CodesButton")
local CodesFunction = ReplicatedStorage:WaitForChild("CodesFunction")
local Frame = CodesGUI:WaitForChild("Frame")
local Redeem = Frame:WaitForChild("Redeem")
local TextBox = Frame:WaitForChild("TextBox")
local IsOpen = false
local player = game.Players.LocalPlayer
local CurrentTween = nil
CodesButton.MouseButton1Click:Connect(function()
if CurrentTween then
CurrentTween:Canel()
CurrentTween = nil
end
local Tween = TweenService:Create(Frame, TweenInfo.new(0.3, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {
Position = (IsOpen and UDim2.new(0.5, 0, 1.5, 0) or UDim2.new(0.5, 0, 0.5, 0))
})
CurrentTween = Tween
Tween:Play()
IsOpen = not IsOpen
end)
Redeem.MouseButton1Click:Connect(function() -- On Mouse click on the redeem button
local Result = CodesFunction:InvokeServer(TextBox.Text) -- Invokes the server, sends the code that the player has put in the TextBox
if Result == 3 then
TextBox.PlaceholderText = "Code successfully redeemed!"
elseif Result == 2 then
TextBox.PlaceholderText = "Code expired!"
elseif Result == 1 then
TextBox.PlaceholderText = "Code invalid/ already redeemed!"
end
TextBox.Text = ""
wait(2)
TextBox.PlaceholderText = "Enter code here..."
end)