I am trying to make a model spawn in when a player types in the model's name into a TextBox and presses an enter button.
The models' names are "apple" and "tree" and they are stored in ServerStorage. (I'm only trying to get the apple model to work right now.) I also have a remote event named JournalEvent in ReplicatedStorage.
I made two scripts, I wanted them to make the apple model appear when the player types "apple" into the TextBox (named "Write") and presses the ImageButton (named "EnterButton")
In StarterGui.JournalGui.JournalFrame I have a local script that says:
local Nouns = {"apple", "tree"} local RemoteEvent = game.ReplicatedStorage.JournalEvent local frame = script.Parent local gui = frame.Parent local items = frame:GetChildren() local sound1 = script.Parent.Success local sound2 = script.Parent.Book local sound3 = script.Parent.Error local player = game.Players.LocalPlayer script.Parent.EnterButton.MouseButton1Click:Connect(function() for i, item in pairs(items) do if script.Parent.Write.Text == Nouns[1] then sound1:Play() sound2:Play() player.PlayerGui.JournalGui.JournalFrame.Visible = false player.PlayerGui.MiniJournalGui.MiniJournalFrame.Visible = true player.PlayerGui.MiniJournalGui2.MiniJournalFrame2.Visible = false player.PlayerGui.JournalGui.JournalBackFrame.Visible = false player.PlayerGui.JournalGui.FailMessage.Visible = false else script.Parent.Parent.FailMessage.Visible = true sound3:Play() wait(4) script.Parent.Parent.FailMessage.Visible = false item.Activated:Connect(function() local itemName = item.Name game.ReplicatedStorage.JournalEvent:FireServer(itemName, game.Players.LocalPlayer:GetMouse().hit.Position) end) end end end)
In ServerScriptService I have a script that says:
local spawn = game.ReplicatedStorage.JournalEvent spawn.OnServerEvent:Connect(function(plr, itemName, hitPos) local item = game.ServerStorage:FindFirstChild(itemName) if item then local itemClone = item:Clone() itemClone.Parent = game.Workspace itemClone:MoveTo(hitPos) end end)
When I run the game, type "apple" into the textbox, and press enter I get an error saying: Activated is not a valid member of TextLabel "Players.BunjiBloxxer.PlayerGui.JournalGui.JournalFrame.Title"
Edit: Idk how I got this error before, now when I run the exact same code I get an error saying: Activated is not a valid member of TextBox "Players.BunjiBloxxer.PlayerGui.JournalGui.JournalFrame.Write"
When I type anything else into the textbox and press enter, nothing happens (which is what I want)
How can I fix this? Thanks
Activated is not a valid trigger from text labels. Your problem should be solved by converting the text labels to text buttons, as text buttons do have Activated triggers. In addition, you can add an if statement to double check that it actually is a TextButton you are trying to call Activated on.
LocalScript in the JournalGui
local Nouns = {"apple", "tree"} local RemoteEvent = game.ReplicatedStorage.JournalEvent local frame = script.Parent local gui = frame.Parent local items = frame:GetChildren() local sound1 = script.Parent.Success local sound2 = script.Parent.Book local sound3 = script.Parent.Error local player = game.Players.LocalPlayer script.Parent.EnterButton.MouseButton1Click:Connect(function() for i, item in pairs(items) do if script.Parent.Write.Text == Nouns[1] then sound1:Play() sound2:Play() player.PlayerGui.JournalGui.JournalFrame.Visible = false player.PlayerGui.MiniJournalGui.MiniJournalFrame.Visible = true player.PlayerGui.MiniJournalGui2.MiniJournalFrame2.Visible = false player.PlayerGui.JournalGui.JournalBackFrame.Visible = false player.PlayerGui.JournalGui.FailMessage.Visible = false else script.Parent.Parent.FailMessage.Visible = true sound3:Play() wait(4) script.Parent.Parent.FailMessage.Visible = false if item.ClassName == "TextButton" then item.Activated:Connect(function() local itemName = item.Name game.ReplicatedStorage.JournalEvent:FireServer(itemName, game.Players.LocalPlayer:GetMouse().hit.Position) end) end end end end)