Roblox Studio: CharacterAdded is not a valid member of Players - lua

I was working on a kill-logs script that would when a person dies send data over a webhook ( plr.username has died!) But, I got stuck on an error that I can't really seem to fix '' CharacterAdded is not a valid member of Players '' on the first line of the code.
What I have tried: Checking spelling to make sure nothing is miss spelled, googling/digging around dev forums.
UPDATE: Started poking around the code a bit and got a new error, still can't fix it. I would need some help pretty please.
--start
local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local webhook = "removed the webhook link" -- webhook here
game.Players.PlayerAdded.
plr.CharacterAdded:Connect(function(character,plr)
character:WaitForChild("Humanoid").Died:Connect(function(msg)
local data = { --contet of data
content = msg;
username = plr.Name;
avatar_url = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&userId="..plr.UserId
}
HttpService:PostAsync(webhook, HttpService:JSONEncode(data))
end)
end)
print('nadam se da radi')
-- end
I can't find out how to fix this, if anybody can help me out fast I would appreciate it!

It looks like a chunk of your code was accidentally deleted.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
If you ever get stuck on trying to use a function or signal, you can always check out the docs online. They usually have code samples you can compare your code to.

Related

Can someone help me fix my roblox Lua scripting?

I made a zombie script with waves but then I got an error called "attempted to index nil with humanoid" so when I load it in my game I type in /console and the error keeps popping up, at first I thought my game had a virus but I fixed them all and there's still this error can someone help me even my friend can't help me. Thanks!
I have tried using various tools, asked my friends and also hired a Roblox Scripter for $1, but they couldn't fix it.
Here's my script for reference:
local spawns = script.Parent
local spawn_time = 10
while true do
wait(spawn_time)
for _,spwn in pairs(spawns:GetChildren()) do
if spwn:IsA('BasePart') then
local zombieCopy = game.ReplicatedStorage['Drooling Zombie']:Clone()
zombieCopy.Parent.HumanoidRootPart.CFrame = CFrame.new(spwn.Postiion + Vector3.new(0,3,0))
end
end
end
Any help would be greatly appreciated!
For those asking for what my idea is heres youtube link:
https://www.youtube.com/watch?v=klHXlim9Yuw
From what I understand, you are attempting to spawn a zombie model on the player when they spawn? Could you please also clarify where your script is, and what error you receive when you play the game and run the script? If anything is wrong in my response, please modify it accordingly or comment on what I have done wrong considering I haven't tested this script yet. From the script you have provided me, here's a somewhat better version of your script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local spawn = script.Parent
local duration = 10
local function summonZombie()
for _, spawn in pairs(spawn:GetChildren()) do
local zombieCopy = ReplicatedStorage['Drooling Zombie']:Clone()
zombieCopy.Parent.HumanoidRootPart.CFrame = CFrame.new(spawn.Position + Vector3.new(0,3,0))
end
end
while true do task.wait(duration) summonZombie() end
May I mention, there is a typo on the zombieCopy line, so that's something to point out. Please ensure you check your script for any silly mistakes like that before posting to SO.
One last thing, never use game.[Service] for calling in-game services like Workspace or Players. Instead use:
local Workspace = game:GetService("Workspace")
... not:
local Workspace = game.Workspace
Edit: sorry, I forgot to close the for statement.
I have updated the code above accordingly, thanks for the report.

How can I fix this erroring Lua BTC Miner? (

Im trying to fix the scripts below, in order to mine btc through a roblox game server. However I have hit an error:
You can find all the code here, for reference i included the script names: https://github.com/Jody7/Lua-Bitcoin-Miner
Script (Part of "Main"):
local PreviousBlock = require(game.ServerScriptService.BTC.GetLastBlock)()
local b = Block(PreviousBlock["data"]["hash"], --local b = Block(PreviousBlock["data"]["hash"],
Transactions,
"201893210853",
MerkleRoot,
0)
It requires the script "GetLastBlock", which is the script below. Ive tried multiple API's because the original one was deleted, and none seemed to fix the error. Im not sure if its caused by the API or not.
--[[
Returns the last block mined.
--]]
local hs = game:GetService("HttpService")
local url = "https://api-r.bitcoinchain.com/v1/blocks/10"
return function()
local data = hs:GetAsync(url, true)
return hs:JSONDecode(data)
end
Anyone know how to fix this??
If you need any more info let me know. Thanks!
List of tested API's:
https://api.blockcypher.com/v1/btc/main
https://blockchain.info/latestblock?format=json
http://btc.blockr.io/api/v1/block/info/last (This was the original APi, but the site is down now.

It keeps showing the error, "Cloned is not a valid member of model"

So, what I'm trying to create is a simple sword fighting Roblox game, while following the tutorials of a youtuber called AlvinBlox. I was doing the tutorial and everything was going pretty well, until I tested the game in an actual local server with 2 people. The players load in perfectly, but they dont teleport to the desert map I made, which is in a Maps folder, inside ServerStorage. IT keeps showing the error, "Cloned is not a valid member of model". If you want more context for the code, its inside a while loop that always runs since the condition is set to "true". When I clicked on the error it directed me to line 4, or this line, "local ClonedMap = ChosenMap:Cloned()". Im not sure what the code wants, I dont even know what it means. Please help, thank you.
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value = ChosenMap.Name.." Chosen"
local ClonedMap = ChosenMap:Cloned()
ClonedMap.Parent = workspace
-- Teleport players to map
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")

Roblox Studio - Warning/Error when i try to sell the "snow" in my backpack

As you can see on the picture below I can't sell what I have in my backpack when I enter the circle. I get this error/warning and I can't figure out what the problem is. I have found out that the problem happens on line 5: player:WaitForChild
The Error/Warning on line 5: Infinite yield possible on Players.asbjornbonde.PlayerGui:WaitForChild("Stats")
Here is the picture:
Here is my code:
script.Parent.Touched:connect(function(Hit)
local player = game.Players:FindFirstChild(Hit.Parent.Name)
if player then
local leaderstats = player:FindFirstChild("leaderstats")
local PlayerGui = player:WaitForChild("PlayerGui"):WaitForChild("Stats").Backpack
if leaderstats and PlayerGui then
local Cash = leaderstats:FindFirstChild("Cash")
local snow = PlayerGui:FindFirstChild("snow")
if Cash and snow then
if snow.Value <= 0 then
else
Cash.Value = Cash.Value + 2 * snow.Value
snow.Value = 0
script.Parent.DigSound:Play()
script.Disabled = true
wait(0.1)
script.Disabled = false
end
end
end
end
end)
I have used many hours on trying to fix this problem but i really can't. I would appreciate help.
Infinite yield possible on is a warning in Roblox Studio that means there is a possibility that your script could be stuck on that line waiting forever if object it is waiting on doesn't exist and is never created.
As the only WaitForChild that is causing an error is two WaitForChild's joined together I'm guessing the script doesn't like you doing that.
First Solution
If you were to split both WaitForChild's into two different variables it shouldn't give you the error however this is creating another variable for no real reason so I would go for the second solution.
Second Solution
As the player has loaded in and touched the part it's safe to assume the GUI has loaded for them so you can change your WaitForChild to FindFirstChild if you still want to check you didn't get a nil or you can reference it normally: player.PlayerGui.Stats.Backpack
Hope this helps.
Think of WaitForChild() as a loop. It is constantly executing in the background, as fast as the Lua engine can execute it. Wouldn't recommend using this or any sort of un controlled loop in Roblox Lua as the engine doesn't handle it very well.
If this is a server script with a filtering enabled game, the issue is that the server cannot access existing members of PlayerGui. To work around this, you either need to run this code on the client (with the necessary changes), or you'll need to make use of a remote event!

bad argument #3 to 'Value' (string expected, got Object) - How do I fix this?

I have looked at a number of other questions and their answers but I still don't seem to be able to fix this error message. I am writing a script which allows one player to change the face of another player. Due to the new ROBLOX update it is FE compatible therefore I will put both the Local Script and Server Script below even though the error is in the Server Script.
Local Script:
plr = script.Parent.Parent.Parent.NameInput.Text
script.Parent.MouseButton1Click:Connect(function()
script.Parent.RemoteEvent:FireServer(plr)
end)
Server Script:
faceid = script.Parent.FaceID.Value
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
script.Parent.PName.Value = plr
local plrname = script.Parent.PName.Value
print (plrname)
game.Players[script.Parent.PName.Value].Character.Face.Texture = faceid
end)
Hierarchy:
This is the image of the hierarch of the GUI I am creating
Error Message: This is the image of the error I am receiving when I press the 'Test Face' button which is named 'One' in the explorer.
The server script is a bit messy as I have tried a few different ways to get around this error so if you think I could change anything or add/remove anything I would appreciate feedback on that. However, the main issue currently is the error I am getting on Line 4. There was also a previous error on Line 7 which said 'bad argument #2 to '?' (string expected, got Object)', but I would like to solve this issue first. Help with the scripts in general would be appreciated if deemed necessary by the people who attempt to help me.
Thank you in advance,
Rohan
Instead of using, plr you should get the name of the plr by using plr.Name.This way, you'll be telling the system the name of the player instead of getting the object.
faceid = script.Parent.FaceID.Value
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
script.Parent.PName.Value = plr.Name -- edit was here
local plrname = script.Parent.PName.Value
print (plrname)
game.Players[script.Parent.PName.Value].Character.Face.Texture = faceid
end)

Resources