Error with getting TextBox data and manipulating it - CLOSED - - lua

Before I start, I will say that there are no error messages in the console, of any type. Anyway, I have been trying to make a user tools game where a player can look at their avatar, look like them, etc. It used to work well in the default Roblox chat, but since that gets moderated, I made a "chat bar" for my game. However, now only one of these functions works (AvatarInspectMenu with a UserId, and not a username). Take a look for yourself:
-- client script
local Players=game:GetService("Players")
local Player=Players.LocalPlayer
local StarterGui=game:GetService("StarterGui")
local GuiService=game:GetService("GuiService")
local Rep=game:GetService("ReplicatedStorage")
repeat wait(0.1) until Player.Character
local h=Player.Character:WaitForChild("Humanoid")
StarterGui:SetCore("TopbarEnabled",false)
local ChatBar=Player.PlayerGui:WaitForChild("ScreenGui").Frame.BoxFrame.Frame.ChatBar
GuiService:SetInspectMenuEnabled(false)
local CS=game:GetService("ContextActionService")
CS:BindAction("Chat Focus",function()
ChatBar:CaptureFocus()
end,false,Enum.KeyCode.Slash)
function ID(str)
if tonumber(str)~=nil then
return tonumber(str)
else
return Rep.Idify:InvokeServer(str)
end
end
ChatBar.FocusLost:Connect(function(entr)
if not entr then return end
ChatBar:ReleaseFocus(true)
local m=ChatBar.Text
ChatBar.Text=""
if m=="!reset" then
Rep.Desc:InvokeServer(Player.UserId)
end
if h.Sit then
if #string.split(m," ")==1 then
local id=ID(m)
if h.SeatPart.Name=="AvatarInspectMenu" then
GuiService:InspectPlayerFromUserId(id)
end
if h.SeatPart.Name=="Become" then
local Desc=Rep.Desc:InvokeServer(id)
h.Sit=false
end
if h.SeatPart.Name=="Tep" then
local P,J=Rep.Join:InvokeServer(id)
if not (P and J) then return end
game:GetService("TeleportService"):TeleportToPlaceInstance(P,J,Player)
end
end
end
end)
-- server-side script
local cache={}
local rep=game:GetService("ReplicatedStorage")
rep.Idify.OnServerInvoke=function(_,n)
if cache[n] then return cache[n] end
local player=game.Players:FindFirstChild(n)
if player then
cache[n]=player.UserId
return player.UserId
end
local id
pcall(function ()
id=game.Players:GetUserIdFromNameAsync(n)
end)
if not id then return 156 end
cache[n]=id
return id
end
local dcs={}
rep.Desc.OnServerInvoke=function(p,n)
if not dcs[n] then
pcall(function()
dcs[n]=game:GetService("Players"):GetHumanoidDescriptionFromUserId(n)
end)
end
p.Character.HumanoidRootPart.CFrame=CFrame.new(0,10,0)
if not dcs[n] then
p.Character.Humanoid:ApplyDescription(game:GetService("Players"):GetHumanoidDescriptionFromUserId(156))
return false
else
p.Character.Humanoid:ApplyDescription(dcs[n])
return true
end
end
rep.Join.OnServerInvoke=function(_,n)
local id,jb=nil
pcall(function()
id,jb=game:GetService("TeleportService"):GetPlayerPlaceInstanceAsync(n)
end)
if id and jb then return id, jb else return nil end
end
I've looked through the code, but I can't seem to find any problems (Except, of course, that there is no error message while trying to attempt a teleport in Studio). Help would be greatly appreciated!
Edit: This code is fully functional. No more help is needed! :D

If there is no error then it works, maybe you missed something out which wasn't called, try adding some prints within functions to see if it prints.

Related

Why is my script not being able to kick a user?

This script is designed so that when you say "!kick [user]" it kicks that user from the game. But, when I test it out, nothing happens with no errors in the output box. Whats going on?
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(player,message)
if player.Name == "playername" then
local words = string.split(message," ")
if string.lower(words[1]) == "!kick" then
words[2]:Kick("You have been kicked.")
end
end
end)
end)
Thanks
The reason nothing is happening right now is because your very first check is failing. You have the parameters for the Player.Chatted connection backwards. The message comes first and the recipient comes second. So what you've named player is actually the message and if player.Name == "playername" then is likely failing because strings don't have a Name property and player.Name is nil.
After that, the next issue you will run into is that after you've split the command into two parts, the second half of the command is still a string, and not a Player. So you need to find a Player with a matching name as the input string.
Try something like this:
local Players = game.Players
local function findPlayerByName(name)
-- escape if nothing is provided
if name == nil then
return nil
end
-- check if any players match the name provided
local allPlayers = Players:GetPlayers()
for _, player in ipairs(allPlayers) do
if player.Name == name or string.lower(player.Name) == name then
return player
end
end
-- couldn't find any players that matched
return nil
end
-- define all the players that can use commands
local admins = {
["playername"] = true,
}
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, recipient)
if admins[player.Name] then
local words = string.split(message, " ")
local cmd = string.lower(words[1])
if cmd == "!kick" then
local playerName = words[2]
local targetPlayer = findPlayerByName(playerName)
if targetPlayer then
targetPlayer:Kick("You have been kicked.")
end
end
end
end)
end)

wait for child not working (roblox studio)

local find = script.Parent
find.Touched:Connect(function(touched)
local de = find:FindFirstChild("Humanoid")
if de == true then
print("we found a human!")
end
end)
is not working?? I'm new to this but i just don't understand!
The reason why your script is not functioning as intended is because :FindFirstChild() will return an object. (not a boolean)
So your statement is practically stating
local part = Instance.new("Part")
if part == true then -- Part does not equal true
The solution is quite simple. When :FindFirstChild() doesn't find anything it will return nil. So just make sure that it `~=~ nil
local find = script.Parent
find.Touched:Connect(function(touched)
local de = touched.Parent:FindFirstChild("Humanoid")
if de ~= nil then -- checking if a humanoid was found
print("we found a human!")
end
end)
If you are trying to detect if a player was joined then Try use this code:
local find = game:GetService("Players")
find.PlayerAdded:Connect(function ()
print("we found a human")
end)
Copy it into your LocalScript and place your LocalScript in StarterGui library
Learn more about Players here -
Learn more about LocalPlayer/Player here
If that's not what you meant to, I will edit the answer.

Attemp to call a nil value (field ‘ShowInventory’) [ESX2]

I just installed ESX 2 into my new server, im Really new at lua and i dont really know what i should do with some resources or how to start coding
I wan to work in the inventory system based on es_extended, but, it doesnt work.
I press the Inventory Key informed in the cofig file \server-data\resources\es_extended\config\default\config.lua
“Config.InventoryKey = “REPLAY_START_STOP_RECORDING_SECONDARY” – Key F2 by default”
module.InitESX = function()
module.RegisterControl(module.Groups.MOVE, module.Controls[Config.InventoryKey])
module.On('released', module.Groups.MOVE, module.Controls[Config.InventoryKey], function(lastPressed)
print("Comment before show The Inventory")
ESX.ShowInventory()
-- if Menu.IsOpen ~= nil then
-- if (not ESX.IsDead) and (not Menu.IsOpen('default', 'es_extended', 'inventory')) then
-- ESX.ShowInventory()
-- end
-- end
end)
end
I literally change a little bit the code to directly execute the ShowInventory() Function but i got this error
the original code look like this
module.InitESX = function()
module.RegisterControl(module.Groups.MOVE, module.Controls[Config.InventoryKey])
module.On('released', module.Groups.MOVE, module.Controls[Config.InventoryKey], function(lastPressed)
if Menu.IsOpen ~= nil then
if (not ESX.IsDead) and (not Menu.IsOpen('default', 'es_extended', 'inventory')) then
ESX.ShowInventory()
end
end
end)
end
but when i press the key dont do nothing and doesnt show anything in the console.

Roblox In-Game Ban System

I am trying to make an in-game system for banning players. I have a button that fires a remote event with a player's name and a message for why they were banned. But every time I hit the button, I get this error :
ServerScriptService.Event_Handler:21: attempt to call a nil value
I have no idea why this is not working can someone help me understand what's going wrong?
EVENT_HANDLER
local dss = game:GetService("DataStoreService")
local bands = dss:GetDataStore("banDataStore")
BanPlayer.OnServerEvent:Connect(function(player, playertoban, reason)
local pui = player.UserId
local success, errormessage = pcall(function()
bands:SetAsync("Banned-", pui, true)
end)
if success then
print("Player Successfuly Banned")
end
game.Players:FindFirstChild(playertoban):Kick(reason)
end)
Since you are searching for players by name, it's possible that you could be spelling the name wrong. In that case, game.Players:FindFirstChild() will return nil. You can sanitize this call by making sure that the player exists before calling Kick()
Also, as a side note, it looks like you are banning the player that calls the BanPlayer RemoteEvent, not the one whose name is stored in playertoban.
local dss = game:GetService("DataStoreService")
local bands = dss:GetDataStore("banDataStore")
BanPlayer.OnServerEvent:Connect(function(player, playertoban, reason)
-- check that playertoban is a real player's name
local bannedPlayer = game.Players:FindFirstChild(playertoban)
if not bannedPlayer then
warn("Could not find a player named " .. playertoban)
return
end
-- record their user-id so we can ban them when they rejoin
local pui = bannedPlayer.UserId
local success, errormessage = pcall(function()
bands:SetAsync("Banned-", pui, true)
end)
if success then
print(playertoban .. " Successfully Banned")
else
warn(string.format("Failed to ban %s permanently with error : %s", playertoban, errormessage))
end
-- remove them from the game
bannedPlayer:Kick(reason)
end)

How to fix an end expected error near eof

I made a cash for kill script in Roblox, but wanted to go further than that and implement a script where when a player has a gamepass, then that player would recieve more cash than another normal player would.
This is for a battle royale styled game in Roblox, and when I playtested it, there were no errors, but the script didn't work.
game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue",folder)
currency1.Name = "Cash"
local increment = 50
if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,7382818)then
increment = increment + 50
end
player:WaitForChild("Humanoid").Died:connect(function()
local tag = player.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local killer = tag.Value
if killer ~= nil then
-- Find the killer's leaderstats folder
local killerStats = killer:FindFirstChild("leaderstats")
if killerStats ~= nil then
-- Find the killer's Cash IntValue
local killerCash = killerStats:FindFirstChild("Cash")
-- Increase cash as before
killerCash.Value = killerCash.Value + increment
end
end
end
end)
I expected a VIP player, who has the gamepass, to receive more cash, but when I tested it, no player received any cash for killing another player at all.
How to fix an end expected error near eof
If the Lua interpreter complains about a missing end you`re missing it somewhere.
Read through your code and make sure everything that is supposed to be closed with an end has one. Read through the Lua Reference Manual to find out which keywords need an end.
In your code it's if statements and function definitions. Checking each pair from inside out you'll end up one end) short to close this game.Players.PlayerAdded:connect(function(player) as mentioned in the comments.

Resources