Make NPC Look Like a Player in ROBLOX - lua

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.

Related

Gun not giving damage to player but showing to the person who fired gun that player is dead

so I have this code at a local script but when I shoot someone it shows for me that the person is dead but for the person and other players the player that was shot is still alive. the handgun script is at a localScript.
You can use remote events in replicatedstorage. So do
game.ReplicatedStorage.Eventname:FireServer(put variables here,2nd variable)
and then on a new server script (can be in the gear) do:
game.ReplicatedStorage.Eventname.OnServerEvent(this would be the player,now comes the variables)
--put whatever you want here
end)
It's been a while since i made anything on roblox so this may not work.

How to make it so i can only mine a part when i have a specific tool in my hand? (Roblox Studio)

I am making a mining game on roblox and i need a mechanism where i can mine ore only when i have a pickaxe equipped and i want it to play a animation and sound when i am mining. I am fairly new to scripting in roblox. I mostly have done models but decided to make this game. Here's the code i made to get it started. I have some variables assigned such as the tool and animations.
tool = script.Parent
local r6anim = game.StarterPack.Pickaxe["Pickaxe Anim R6"]
local r15anim = game.StarterPack.Pickaxe["Pickaxe Anim R15"]
tool.Activated:Connect(function()
end)
This might be a bit late but here goes
U wanna have a localscript in ur tool and a normal script in serverscriptservice call them anything u want
Next step make a remote inside of replicated storage name this something easy to remember
The logic here is when a player equips the pickaxe tool u can set a var = true allowing them to mine as long as u have it equiped u can do that with the tool.equiped:connect(function) and when u unequip it do tool.unequiped etc
Make a var referencing ur remote u made earlier by doing local myremotething = game:getservice("replicatedstorage").remotenamehere
Then inside of ur tool.activated func u wanna do
Myremotething:FireServer()
Then u can code the server ens to handle all ur animations and setup stuff thats the general way to do it i will make a test game later today and reply to u sry for vague answer im on mobile lolol

Roblox studio finding a player in the players folder using a touched event

I have made a gamepass for my game and I have made a door that leads to a restricted area that you only can access with the gamepass but if someone who owns the gamepass opens the door then everyone can come in. When a new player joins they are given a boolean value that evaluates to false if the player don't own the gampass and true if they do own it. The problem is that the boolean value is put in the player that is in the player folder so when I set up a detector to check if the player owns the gamepass the touched event only gives me the information about the player that is in the workspace, and in the workspace player there is no boolean value to check if they have the pass. So somehow i need a way to find the player that is in the players folder using a touched event.
I don't really have any code to show because I didn't really think any ideas that I came up with would work and those that I did try didn't work.
Example from the Roblox staff:
part.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
-- do stuff
end
end)

Cannot Access Text In A Roblox TextBox

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.

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