Cannot Access Text In A Roblox TextBox - lua

Whenever I try to do this set of code in robloxian lua, I can't access the textbox. This code is suppost to do this, but I think that its accessing the property of the text inside the textbox instead. Here is a somewhat representative of the code that I am using. So, lets say that Bob wants to talk to John. I would write it like this.
game.StarterGui.ScreenGui.Frame.JohnsSpeech.Text = game.StarterGui.ScreenGui.Frame.JohnsUserSetText.Text
Now, JohnsUserSetText is the textbox, and JohnsSpeech is the speech. But when I try to do this, it doesn't work. It just says whatever the text is in the properties. Any help would be appreciated. Thanks! And have a great rest of your day!

Supposed to do what?
.Text is a property of a textbox or anything similar
NOTE: You are changing a starter gui, which means anyone using that current gui won't get the updated one until they die and respawn. If you want to update the one in their GUI access it through Game.Players.playernamehere.PlayerGui
StarterGui is what the game imports into a player when it reloads everything AKA: respawning or joining
if you need tips on updating each players Gui tell me and I can give some examples

Much as M. Ziegenhorn is saying, your issue is that you're referring to the StarterGui, not the PlayerGui.
The StarterGui is the container containing the default GUIs to be given out to the player upon spawn, while PlayerGui (game.Players.Ravenshield.PlayerGui, for instance) is where the GUIs are stored for each player.
The PlayerGui can only be accessed through a LocalScript.
The easiest way to access your PlayerGui is obviously to just place the LocalScript inside the ScreenGui you're using.
Otherwise, you can also access it easily by doing game.Players.LocalPlayer.PlayerGui
If I were to put my LocalScript directly in the ScreenGui we're using, it could look like this:
local TextBox = script.Parent.TextBox
local SpeechLabel = script.Parent.SpeechLabel
SpeechLabel.Text = TextBox.Text
However, you probably want to add text whenever they write it into the TextBox. Then we need to take a look at the documentation for ROBLOX, and specifically the TextBox Object.
If you scroll down to the Events, you can take a look at the TextBox.Changed event. This will fire everytime a property of the TextBox changes.
We could also use TextBox.FocusLost, which fires when the client has unfocused the TextBox. The event supplies a boolean 'enterPressed' which tells us whether or not the client pressed enter to lose focus.
local TextBox = script.Parent.TextBox
local SpeechLabel = script.Parent.SpeechLabel
TextBox.FocusLost:Connect(function(enterPressed)
if enterPressed then -- Checking if the enterPressed is true and not nil
-- The user must have pressed enter to exit the TextBox.
-- Could mean that they're done writing something.
SpeechLabel.Text = TextBox.Text
end
end)
All events have to be bound by using the :Connect method. This is what tells ROBLOX to start 'listening' to the event, to make sure the function fires every time this occurs.

Related

Why don't Proximity Prompts work without a character?

I'm in a pickle. (not literally, of course)
I had a ship game, which used Proximity Prompts to enter the docks. This worked well enough. However, that was for a click to move system, and now I'm attempting to make a direct control system (e.g. you press WASD to move your ship instead of clicking a point on the ocean), and as such, there is no character in the game, and have done everything else without a character.
In short: They don't work now and I have no clue why.
The script is near enough the exact same on both games (The original game's script has a lot more other functions in it, but nothing that would affect this), and so is the configuration of the Proximity Prompt. But I don't see how it could be to do with the lack of a player Character, and if it is, how do I edit the default code for it, to work without one? (I had a look, but couldn't find anything useful) As it doesn't seem like it will have direct dependence on the character, as any animations or custom behaviour would have to be done connecting to the ProximityPromptService/Prompt itself to add those via the events.
This is literally the whole server-side script I have for it.
local proximitypromptservice = game:GetService("ProximityPromptService")
local function get_player_data (player)
... --Unrelated, it's just a function to get player data, no issues here.
end
proximitypromptservice.PromptTriggered:Connect(function(promptobject,player)
print("Prompt TRIGGERED") --Not seen in the log when the Prompt is pressed.
if promptobject.Name == "DockControl" then
print("DOCKCONTROL")
if player.IsLoading.Value == false then
game.ReplicatedStorage.Dock.AccessDock:Fire(player,...)
end
end
end)
It's probably worth noting that when you press the key, e.g. E, it does the hold Duration animation and then disappears, and reappears as you'd normally expect. Creating a custom docking system is not out of the question, but I would really really prefer not to create an overcomplicated, clunky system for something that should work out of the box.
Any help would be appreciated,
The Frog.
PS: Also tried this on both local and server scripts as a child of the prompt to no avail.
script.Parent.Triggered:Connect(function()
print("TRIGGERED")
end)

How do you find all the objects/instances in a folder/model with a specific attribute in lua/roblox lua

I am working on a game in Roblox and need a little help finding objects with attribute values. It is a tycoon for anyone here familiar with Roblox. I would like to know how you can find all instances with say the attribute Unlock_ID: 1, and then when you press the corresponding button, it will unlock it, or make it show up on the screen. I know how to make the objects unlock, I just don't know how to get all the objects with that attribute.
To put it more simply:
I want to find all the objects/instances inside a section with a specific attribute and a specific value and put them inside a table.
I hope this makes sense.
You can use a for i,v in ipairs loops along with the Folder:GetChildren() as your iteration directory. Then you can insert the instance (using table.insert(table,element) into a table if their part:GetAttribute('Unlock_ID') is equal to 1. To achieve this, simply do the following:
local partsWithAttribute = {}
local folder = workspace.Folder -- change this to whatever path you want to iterate through
for i,part in ipairs(folder:GetChildren()) do
if part:GetAttribute('Unlock_ID') == 1 then
table.insert(partsWithAttribute,part)
end
end

Why isn't this roblox dialog script working

so I want the game to take a specific action when a dialog option is selected.
script.Parent.DialogChoiceSelected:connect(function(player,choice)
if choice.Name == "No" then
player.Character.Humanoid.Health = 0
elseif choice.Name == "Yes" then
player.Character.Humanoid.Health = 1000
end
end)
The script is enabled, it's placed in the same dialog event as the choices, and I know the dialog names are correct, but when the dialog choice is selected absolutely nothing happens. So someone please explain to me how the ****
Taking a look at the docs for Dialog.DialogChoiceSelected there's this line :
This event is client-side only and will not fire on the server. It should be connected to in either a LocalScript or a ModuleScript required by a LocalScript.
So you'll need a LocalScript in one of the appropriate locations to connect to this Dialog object and then your code should work properly.
If you put a script in your dialog, it wouldn't work because it is client-side so it has to be a LocalScript and it has to be a descendant of either:
A Player's Backpack, such as a child of a Tool
A Player's character model
A Player's PlayerGui
A Player's PlayerScripts
The ReplicatedFirst service.
And then change the local script's code to be workspace:WaitForChild("TheDialogName").
https://developer.roblox.com/en-us/api-reference/class/LocalScript
https://developer.roblox.com/en-us/api-reference/class/Dialog

Make NPC Look Like a Player in ROBLOX

I am trying to make a NPC look like a player for a title screen.
I don't need a tutorial on how to make an NPC; I know how to make an NPC look like someone. Instead, I need to know how to clone the exact appearance of a player within a script. How can I do this?
First of all, a given player's character model can be found at a Player's .Character attribute. The .Character attribute is a Model, which, along with most other kinds of objects in the game, has a :Clone() function. You can use this function to make a complete copy of the player's character model. For example:
player = path.to.player.here
copy = player.Character:Clone()
copy.Parent = game.Workspace --put the clone into the physical environment
However, there is a catch if you are using this for a title screen like you said: when a player joins the game, their character will not load immediately; instead, it will take a few seconds. You can probably see this for yourself if you trying playing a game and then pay attention to how long it takes before you are actually placed into your character. Because of this, if you try to use .Character right when someone joins your game, your code will break. To account for this, you can use a special features of ROBLOX called Events.
ROBLOX has special objects called Events. Events have a special :connect() function, which allows you to connect functions to those events. When you connect a function to an Event, that function will be executed when the Event occurs.
In your case, you will need two Events:
one for when a Player joins the game
one for when their physical .Character model has actually loaded
First of all, let's talk about when a Player joins the game. First, we need to get the Players object—an object that keeps track of information about all of the players. We will use a special function of game called :GetService():
players = game:GetService("Players")
Now, we will use a special Event in Players called .PlayerAdded:
players = game:GetService("Players")
players.PlayerAdded:connect(function(player)
end)
Notice that the Player that was actually added will be passed as an argument to the parameter player. Now, we will use a special Event of Players called CharacterAdded:
players = game:GetService("Players")
players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
end
end)
Notice that the Character of the Player will be conveniently passed as an argument to the parameter character, so we don't even need to use Player.Character. Now, we can take our cloning code from earlier and finally put it inside this code:
players = game:GetService("Players")
players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local copy = character:Clone()
copy.Parent = game.Workspace --put the clone into the physical environment
--your code here
end
end)
And that's it! Now you can put all of your code that deals with the clone in place of --your code here.
One final note is that this needs to be done in a regular Script, not a LocalScript. Scripts are handled by the ROBLOX server, whereas LocalScripts are handled by the players' computers themselves. Because the server handles players being added to a game, you must use a Script.
Hope this helps!
I'm going to assume that you're trying to make a NPC looking like a player? This can take a bit of work, but you have to find the player in the game.Workspace that you want the NPC to look like, then you can either clone the player and insert the npc's parts into it, or you can just insert the cloned player into the npc.
As far as I see it, there isn't a way to do this without doing it within a script.

How to see if a player got a specific tools in ROBLOX

I am working for a Airport in Roblox and I need a script that when I click on a button, the script check if I have a specific tools in my inventory (In this case a suitcase). If I got the suitcase, the player who click on the button get the suitcase removed from his inventory. I don't want that the entire inventory get removed, only the tool. I want also that the suitcase respawn on a specific place. (On the conveyor.(Please, use X,Y,Z to respawning the suitcase)) I know this isn't a easy script but if someone know how to do it, I will be really happy.
All you need to do is check if the suitcase is nil, which is simple:
local suitcase = player.Backpack:FindFirstChild("Suitcase")
if suitcase == nil then
--suitcase is nil!
else
--suitcase is not nil!
end
I used the FindFirstChild() function, which finds the first child of whatever's calling it specified, to see if the suitcase was nil or not. If there is no such child parented to the caller, FindFirstChild() returns nil.

Resources