So I followed this one DevKing tutorial to make an animation and for some reason I cant get it to work, because I got this error: attempt to index nil with 'Humanoid'
This is my code:
local player = game.Players.LocalPlayer
local char = player.Character
local Hum = char.Humanoid
local ArmAnim = script.ArmAnim
local ArmTrack = Hum:LoadAnimation(ArmAnim)
ArmTrack:Play()
I have already tried rereading all of my code and looking back at the video but I cant seem to get it to work.
Your code should work just fine, but you have a timing issue in your code. Based on the comments in the question, since this LocalScript is in StarterPlayerScripts, this script will fire as soon as a player joins. But, when a player first joins the server, their character is not immediately spawned into the world. So there is a short time period where player.Character is nil.
So to fix this issue, you need to wait until the character is loaded into the world.
You can do this in a few different ways.
Move this LocalScript into StarterCharacterScripts. This will change when the script fires to after the character is loaded into the world.
or
Alter your LocalScript to wait for the Humanoid to exist.
local player = game.Players.LocalPlayer
local char = player.Character
-- if the player hasn't loaded yet, wait for the character to spawn into the world
if char == nil then
player.CharacterAdded:Wait()
char = player.Character
end
local hum = char.Humanoid
local ArmAnim = script.ArmAnim
local ArmTrack = hum:LoadAnimation(ArmAnim)
ArmTrack:Play()
Related
I'm trying to make it so that when you use a proximity prompt an image label becomes visible but it's not working, how do I fix this?
local proximity = workspace.Cardpack.ProximityPrompt
local proximityPromptService = game.GetService("ProximityPromptService")
proximity.Triggered:Connect(function()
_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible
end)
You don't really need to use _G for this. Instead, we can directly declare it to the X1.
local prompt = workspace.Cardpack.ProximityPrompt
local x1 = workspace.Inventory.Frame.X1
prompt.Triggered:Connect(function()
x1.Visible = not x1.Visible
end)
_G.visible = not _G.visible game.Workspace.Inventory.Frame.X1.Visble = _G.visible
This is where your script goes entirely wrong. This is not LUA syntax and is not how programming works. This is actually what you are currently trying to do.
local value = true = false;
Really what you should be doing is creating a reference to the ImageLabel you are trying to set. Then change it's properties. Setting a variable in the global enviroment won't change the ImageLabel's properties.
local ProximityPromptService = game.GetService("ProximityPromptService");
local ImageLabel = workspace.Inventory.Frame.X1;
local Proximity = workspace.Cardpack.ProximityPrompt;
proximity.Triggered:Connect(function()
ImageLabel.Visible = true;
end)
This seems to be a simple issue which can be solved with a simple solution (granted you know what you're doing). Now here's some things to note:
You don't need to use the ;'s you see on almost every line people make. It's not something mandatory and shouldn't be. Though it's good for when you want to have less lines (if it's your preference).
You wouldn't want to have 2 ='s on the same line as it's not the correct syntax (as #sl0th has stated), you cannot attempt such a task as it wouldn't even work. You want it to not just change it back to false anyways.
As you code this, I don't believe you fully understand how it works, and to make the code you first of all have to understand COMPLETELY or rather fluently how it works. So let's start off with that!
How do we do this? Let's see:
-- Perhaps put the script INSIDE of the Cardpack, and then do it from here.
-- Also, I'm not sure why you've put an "inventory.Frame" here, if it's a screengui then it should go in StarterGui, however if it's a billboardgui then please ignore me.
local Cardpack = script.Parent -- I've added it inside the cardpack as said.
local Prompt = Cardpack.ProximityPrompt
local Label = workspace.Inventory.Frame.X1 -- using the original directory as I don't know how your explorer looks.
local CanBeVisible = false -- if you want to toggle it.
Prompt.Triggered:Connect(function() -- make sure to look up on devforum about this.
if not CanbeVisible then -- "not CanBeVisible" is equivalent to "CanBeVisible==false".
CanBeVisible = true
Label.Visible = true
else -- if it's true and not false:
CanBeVisible = false
Label.Visible = false
end
end)
This is a more..."Acceptable" way of coding. People have their preferences, but this is generally how I'd do it based on how you did it. IF you don't understand much I'm always here to help, of course! :D
FINAL NOTES:
local A,B = "A", "B" -- you can assign multiple variables on a single line!
A,B = "B", "A" -- and you can also change more than one on the same line too.
local A = "A";print(A) -- that's how ; is used if you want to do more than one thing on the same line (but not done at the the same time on the same line!). ; Seperates the code without needing to add spaces, though adding/casting variables you should stick to using the comma(s) to separate them assigning new values and whatnot.
Also, you don't even need that ProximityPromptService variable as you never even use it! And you can't just do game.GetService(..), you IDEALLY do it as game:GetService(..).
I hope this helped you and if it did, mark this as the answer! Though this is my first time trying to help people I tried my best lol.
I am coding my fist a game with lua on the Roblox Stuido ide. The game works -- sort of--, although I know the code is not great. It's a game for small children in which a number shows on a sign and the player has to go to the platform that matches the number. One of the issues that I have is that I want there to be a GUI that displays the points in big numbers as the leader stats on the top corner are not easy to see. What I want is not just for the player to see their own points this would be somewhat easier, just add a textLabel on the starter player gui with a script like so:
while true do
wait(.1)
script.Parent.Text = game.Players.LocalPlayer.leaderstats.Platforms.Value
end
with the following code too:
game.Players.PlayerAdded:connect(function(player)
local playerKey = "Player_" .. player.UserId
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Platforms = Instance.new("IntValue", leaderstats)
Platforms.Name = "Platforms"
Platforms.Value = 0
platformCount:SetAsync(player.UserId, 0)
StartGui:FireAllClients(player)
end)
Please take note of the last couple of lines of that block, those are what I came up with. I am not sure how to do it better but I sense they are a botch.
My objective is that each player can see not only their scores updated in real time, but also every other player's. This is what is not fully working. My method is as follows. When a player steps on the desired platform I have this code on a local script
allPlats[k].Eliminated = true
player:WaitForChild("leaderstats"):FindFirstChild("Platforms").Value = player:WaitForChild("leaderstats"):FindFirstChild("Platforms").Value + 1 --increase leaderstats
points = points + 1
numIfScored:InvokeServer(column, row, teamColorReady, points, team)
PlatformDeleted.OnClientEvent:Connect(platformTransparency)
Ignore the lines that don't apply to the question. The important part for this question is that I access the intValue created in the leaderstats and increase it's value by one. I also send a call to the server with a remote function that passes where the platform was, the color of the team etc...
The serverside script then uses these values to perform a number of tasks related to setting the next target and updating the way the platforms look and, crucially, sends the data to a datastore:
function numIfScored.OnServerInvoke(plr, col, row, orignalTeamColor, points, team)
game.Workspace.TargetNumber.Value = getAnddisplayTarget(col, row)
PlatformDeleted:FireAllClients(col, row)
for k, v in pairs(allPlats) do
if v.Column == col and v.Row == row then
v.Part.Transparency = 0
v.Part.Material = "Neon"
v.Part.BrickColor = BrickColor.new(orignalTeamColor)
end
end
platformCount:SetAsync(plr.UserId, points)
end
I then run a separate block of code in the same scrip that is constantly updating the gui by grabbing the points from the datastore:
while wait(.1) do
for _, player in pairs(Players:GetPlayers()) do
local points = platformCount:GetAsync(player.UserId)
UpdateGUI:FireAllClients(player.UserId,points, player.Team)
end
end
I have a localscript that is a child of the text label that displays the scores with the following code:
local function UpdateLabel(plrId, points, team)
if team.Name == "Really red Team" then
game.Players.LocalPlayer.PlayerGui.ScreenGui.RedTeam.Text = points
elseif team.Name == "Really blue Team" then
game.Players.LocalPlayer.PlayerGui.ScreenGui.BlueTeam.Text = points
end
end
StartGui.OnClientEvent:Connect(StartLabel)
This works but is buggy. I play at home with my son an it sort of works, with a bit of lag, but as soon as I try to play with other players, like my friend and his son, the system stops working well. One thing that I know is not good is that if you start playing before another player joins, then that player can't see your progress before they came in. Another problem is that the first player that joins will be seen by players that join later, but as players join that can't see the labels of players that joined before.
Is there a much simpler way to create a gui that updates all the players scores in all the players gui's? Thanks.
I can post full code if needed.
No need for full code. I just needed the sentence "It's in a LocalScript". Even if you're changing the text of the labels in a server script, you're adding the points on a local script which means it'll only change the points for you and not any other player. Instead if you use a RemoteFunction and call on the server to change the points, I'm more than certain it should work.
The debugger seems to suppress viewing the contents of a UnicodeString in the Local Variable and Watch windows whenever the current function contains a UnicodeString::Length() call.
Running C++ Builder 10.3 Rio Enterprise (upgraded to 10.31 to try to solve the issue) where I have started a new project, added a button and put the following code in for the button. This a stripped down version of a large piece of code to track down and reproduce the issue.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TFDQuery* qry = new TFDQuery(NULL);
UnicodeString search = "SELECT *\rFROM Client\rWHERE id>0;";
UnicodeString currLine;
int to, len;
qry->SQL->Clear();
to = search.Pos("\r");
while (to > 0) {
currLine = search.SubString(1, to-1);
qry->SQL->Add(currLine);
//len = search.Length()-1; // Offending line
search = search.SubString(to+1, 999999);
to = search.Pos("\r");
}
currLine = search;
qry->SQL->Add(currLine);
}
The picture below shows two different runs of this code. One is exactly as shown above (with one line commented out). The other shows with the line included.
My concern is that the the debugger only shows the apparent address of the variable named "search" and if I expand it, it shows "????", not the contents of the variable as shown by the arrow. Also note, the breakpoint is above the line that causes the debugger to switch views. Any ideas how I can get the contents of "search" to appear if I actually calculate the length of the substring (rather than placing "999999" for its length)?
After some experimenting, I can now partially answer my own question with a potential workaround. Replacing the "search.Length()" with "wcslen(search.c_str())" seems to work, at least it does not have the side effect of displaying only addresses for UnicodeStrings in the watch list and and local variables windows. At this point, I haven't thoroughly tested if this eventually raises some other problem. But why should I have to do this for such a fundamental type to the language?
I've been looking for this answer in the internet for a while and have found other people asking the same thing, even here. So this post will be a presentation of my case and a response to the "solutions" that I have found.
I am such new in Ruby, but for learning purposes I decided to create a gem, here.
I am trying to implement a keyboard navigation to this program, that will allow the user use short-cuts to select what kind of request he want to see. And in the future, arrow navigations, etc.
My problem: I can't find a consistent way to get the keyboard events from the user's console with Ruby.
Solutions that I have tried:
Highline gem: Seems do not support this feature anymore. Anyway it uses the STDIN, keep reading.
STDIN.getch: I need to run it in a parallel loop, because at the same time that the user can use a short-cut, more data can be created and the program needs to show it. And well, I display formated text in the console, (Rails log). When this loop is running, my text lost the all the format.
Curses: Cool but I need to set position(x,y) to display my text every time? It will get confusing.
Here is where I am trying to do it.
You may note that I am using "stty -raw echo" (turns raw off) before show my text and "stty raw -echo" (turns raw on) after. That keeps my text formated.
But my key listener loop is not working. I mean, It works in sometimes but is not consistent. If a press a key twice it don't work anymore and sometimes it stops alone too.
Let me put one part of the code here:
def run
# Two loops run in parallel using Threads.
# stream_log loops like a normal stream in the file, but it also parser the text.
# break it into requests and store in #requests_queue.
# stream_parsed_log stream inside the #requests_queue and shows it in the screen.
#requests_queue = Queue.new
#all_requests = Array.new
# It's not working yet.
Thread.new { listen_keyboard }
Thread.new { stream_log }
stream_parsed_log
end
def listen_keyboard
# not finished
loop do
char = STDIN.getch
case char
when 'q'
puts "Exiting."
exit
when 'a'
#types_to_show = ['GET', 'POST', 'PUT', 'DELETE', 'ASSET']
requests_to_show = filter_to_show(#all_requests)
command = true
when 'p'
#types_to_show = ['POST']
requests_to_show = filter_to_show(#all_requests)
command = true
end
clear_screen if command
#requests_queue += requests_to_show if command
command = false
end
end
I need a light in my path, what should I do?
That one was my mistake.
It's just a logic error in another part of code that was running in another thread so the ruby don't shows the error by default. I used ruby -d and realized what was wrong. This mistake was messing my keyboard input.
So now it's fixed and I am using STDIN.getch with no problem.
I just turn the raw mode off before show any string. And everything is ok.
You can check here, or in the gem itself.
That's it.
trying to get my head around Feedzirra here.
I have it all setup and everything, and can even get results and updates, but something odd is going on.
I came up with the following code:
def initialize(feed_url)
#feed_url = feed_url
#rssObject = Feedzirra::Feed.fetch_and_parse(#feed_url)
end
def update_from_feed_continuously()
#rssObject = Feedzirra::Feed.update(#rssObject)
if #rssObject.updated?
puts #rssObject.new_entries.count
else
puts "nil"
end
end
Right, what I'm doing above, is starting with the big feed, and then only getting updates. I'm sure I must be doing something stupid, as even though I'm able to get the updates, and store them on the same instance variable, after the first time, I'm never able to get those again.
Obviously this happens because I'm overwriting my instance variable with only updates, and lose the full feed object.
I then thought about changing my code to this:
def update_from_feed_continuously()
feed = Feedzirra::Feed.update(#rssObject)
if feed.updated?
puts feed.new_entries.count
else
puts "nil"
end
end
Well, I'm not overwriting anything and that should be the way to go right?
WRONG, this means I'm doomed to always try to get updates to the same static feed object, as although I get the updates on a variable, I'm never actually updating my "static feed object", and newly added items will be appended to my "feed.new_entries" as they in theory are new.
I'm sure I;m missing a step here, but I'd really appreciate if someone could shed me a light on it. I've been going through this code for hours, and can't get to grips with it.
Obviously it should work fine, if I did something like:
if feed.updated?
puts feed.new_entries.count
#rssObject = initialize(#feed_url)
else
Because that would reinitialize my instance variable with a brand new feed object, and the updates would come again.
But that also means that any new update added on that exact moment would be lost, as well as massive overkill, as I'd have to load the thing again.
Thanks in advance!
How to do updates is a bit counterintuitive with the current API. This example shows the best way to do it:
# I'm using Atom here, but it could be anything. You don't need to know ahead of time.
# It will parse out to the correct format when it updates.
feed_to_update = Feedzirra::Parser::Atom.new
feed_to_update.feed_url = some_stored_feed_url
feed_to_update.etag = some_stored_feed_etag
feed_to_update.last_modified = some_stored_feed_last_modified
last_entry = Feedzirra::Parser::AtomEntry.new
last_entry.url = the_url_of_the_last_entry_for_a_feed
feed_to_update.entries = [last_entry]
updated_feed = Feedzirra::Feed.update(feed_to_update)
updated_feed.updated? # => nil if there is nothing new
updated_feed.new_entries # => [] if nothing new otherwise a collection of feedzirra entries
updated_feed.etag # => same as before if nothing new. although could change with comments added to entries.
updated_feed.last_modified # => same as before if nothing new. although could change with comments added to entries.
Basically, you'll have to save off four pieces of data (feed_url,
last_modified, etag, and the url of the most recent entry). Then when you
want to do updates you construct a new feed object and call update on
that.
I think a more obvious solution would be to add :if_modified_since option to fetch_and_parse method of class Feed, see https://github.com/pauldix/feedzirra/blob/master/lib/feedzirra/feed.rb#L116 and https://github.com/pauldix/feedzirra/blob/master/lib/feedzirra/feed.rb#L206
You can reset #rssObject to the updated feed.
feed = Feedzirra::Feed.update(#rssObject)
if feed.updated?
puts feed.new_entries.count
#rssObject = feed
else
puts 'nil'
end
The number of entries in #rssObject will keep growing as new entries are found. So if the first fetch finds 10 entries, and then next finds 10 new entries, #rssObject.entries.size will be 20.
Note that you can do this regardless of whether update finds new entries. If feed.updated? is false, feed will be the original feed object, #rssObject.