#How would I do something like this but have it actually work?
1 messages · Page 1 of 1 (latest)
this code sucks so much
but if you just want to have player in table
you need to do "playername":player.Name
or something like that
but ngl you got problems
I think the issue you have here is when you are writing the dictionary, I believe you need to surround the unique key with brackets, if it's not a number.
local table1 = {["playername"] = player}
however, this logically does not make sense the way you have wrote it
I'll explain how dictionaries work real quick so I can be clear
I believe what you are intending to do is easily grab a player by their name, using a dictionary/table.
However, you don't need to use a dictionary or table here at all.
local Player = game.Players.LocalPlayer
print(Player.Name) -- you can directly access the player's name, you don't need to store it separately. The player's name belongs to them, so you can access it if you have the "Player" object.
If you are trying to learn how to use tables/dictionaries, there are really helpful ways to do this:
ye i already tried that but it did nothing
Let's say I want to create a part, one for each player in my game.
Well, I can use a dictionary to basically remember which part belongs to which player.
In this case, I will take the player's name, which will be the key.
Then, I will take the part I created, and assign that as the value.
local Player = game.Players.LocalPlayer
local PlayerPartsTable = {}
PlayerPartsTable[Player.Name] = Instance.new("Part")
-- Now, I can grab that specific part by searching for it with the player's name:
print(PlayerPartsTable[Player.Name])
-- this will print out the part that I just created, and assigned to the player's name in that table.
well yeah, your code has quite a few issues
read through what I wrote above, hopefully that will help you some
this is a server script btw (ik u dont need bindable events for a server script but im just testing rn)
oh alright, the examples I gave won't work then since I used local player
but just imagine you already had access to a player in your game, the concept will still work
fire a remote from client, the first thing passed over will always be the player object and you get the name from there.
i've read a few post you've made and i would recommend going back to basics or maybe watch brawldevs playlist if you haven't
local Players_List = {
["Player_name"] = Player,
}
https://create.roblox.com/docs/tutorials/fundamentals/coding-5/intro-to-dictionaries
The problems fixed now but I tried that and it didn’t work