Basically, I have a part in Workspace which has a ProximityPrompt inside of it, and once the player interacts with it a GUI appears that has a TextBox.
I wanted to make it so that if the player puts in a specific Text inside the TextBox and hits enter, a sound will play + a MeshPart in ReplicatedStorage will be positioned to a specific location in the game.
The thing is, I want all of this to just be local, so that other players can’t see it in-game.
First, if you may need to make the TextLabel client only. So Instance.new(“TextBox”) and parent it, whatever, then you can set up a simple detector local script:
local textBox = script.Parent
local function FocusLost()
print("Focus Lost!")
end
textBox.FocusLost:Connect(FocusLost)
Edit: I forgot if you need this to be client sided (instance.new) or if you can just use it from the server. I think you can though.
Edit2: You don’t need onFocused, since we only care about the text after it has been updated, FocusLost is better.
Local scripts are kinda in the name, they’re like your local neighborhood you know? Basically, only the player who is running the local script will see the changes.
That’s good, but I think you forgot one of the parameters. The enterpressed boolean will check whether or not the focus was lost by pressing enter, which is what I think OP wants:
local textBox = script.Parent -- Set up textbox variable here
local function FocusLost()
print("The player has lost focus of the TextBox, check the variable now.")
if textBox.Text == "String" then
print("It's correct!")
-- Run extra code here if needed
end
end
textBox.FocusLost:Connect(FocusLost)
Oh you mean like activating it in one line? You don’t really need it but sure, we can put it in.
Full script:
local textBox = script.Parent -- Set up textbox variable here
local key = "String" -- Set this to be what string you want to check
textBox.FocusLost:Connect(function(inputThatCausedFocusLoss)
print("The player has lost focus of the TextBox, check the variable now.")
if textBox.Text == key then
print("It's correct!")
-- Run extra code here if needed
end
end)
LocalScript inside TextBox: (Sound is also inside TextBox so that it plays locally)
local textBox = script.Parent
local sound = script.Parent.Sound
local rs = game:GetService("ReplicatedStorage")
local model = rs:WaitForChild("OrangeCoin")
local pos = game.Workspace.MusicPartTP.CFrame
textBox.FocusLost:Connect(function(enterpressed)
if textBox.Text == "CODE" then
print("It's correct!")
sound:Play()
model.Parent = workspace
model:SetPrimaryPartCFrame(pos.CFrame)
end
end)
ServerScript inside ProximityPrompt: (SongGUI is also inside ProximityPrompt)
local prompt = script.Parent
prompt.Triggered:Connect(function(player)
if player then
local SongGui = player:WaitForChild("PlayerGui"):WaitForChild("SongGUI")
SongGui.Enabled = true
end
end)
Close, with the enterpressed parameter on the focuslost event, you aren’t actually doing anything with it, the whole reason of that parameter is to check if the focus was lost by someone clicking the enter key so just add this line of code:
textBox.FocusLost:Connect(function(enterpressed)
if enterpressed == true and textBox.Text == "CODE" then
print("It's correct!")
sound:Play()
model.Parent = workspace
model:SetPrimaryPartCFrame(pos.CFrame)
end
end)
For some reason the GUI doesn’t appear when I click the proximityprompt, did I do a mistake in the serverscript inside the proximityprompt? or is it because the GUI is inside the proximityprompt?
I have created what you mentioned. You will need to tweak some things.
local proximityPrompt = workspace.Part.ProximityPrompt -- path to proximityprompt
local replicatedStorage = game:GetService("ReplicatedStorage")
local textBox = script.Parent.TextBox -- path to textbox
local meshpart = replicatedStorage:WaitForChild("MeshPart") -- path to meshpart
local sound = replicatedStorage:WaitForChild("Sound") -- path to sound
proximityPrompt.Triggered:Connect(function()
textBox.Visible = true
end)
textBox.FocusLost:Connect(function(enterPressed)
if enterPressed and textBox.Text == "meow" then -- put specific text here
meshpart.Parent = workspace
meshpart.Position = Vector3.new(0, 0.5, 0) -- put position here
sound:Play() -- play sound
end
end)
Here is a file including the proximity prompt, gui, sound, and mesh part: meow.rbxl (53.7 KB)
That means for some reason songGUI doesn’t exist, did you put the songgui in startergui so that it would replicate to each player’s playergui? Or you might’ve misspelled?