You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Twitter code UI, I have everything done, it was working, then suddenly this happened:
What is the issue?attempt to index field '?' (a nil value)
on this line:
local players = game:GetService("Players")
local dataStore2 = require(1936396537)
local CodeStoreName = "TwitterCodes"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function setupUserData()
local Codes = {
["YEET1"] = {Used = false, Reward = 500}
}
return Codes
end
ReplicatedStorage.TwitterCode.OnServerEvent:Connect(function(player, input)
local Codes = dataStore2(CodeStoreName, player):Get(setupUserData())
if Codes[input].Used == false then -- this line
What solutions have you tried so far? I tried putting tostring(), nothing changed.
Every help from you is appreciated, I’m sure I pass the input so, I have no idea where the problem can be.
If are you wondering, this is the client side:
local RS = game:GetService("ReplicatedStorage")
local code1 = "YEET1"
script.Parent.MouseButton1Click:Connect(function()
local input = script.Parent.Parent.Parent.CodeEnter.TextBox.Text
if input ~= "" or nil then
if input == code1 then
RS.TwitterCode:FireServer(input)
The input here is blue like it is some keyword, in studio it doesn’t show it like this.
oh roblox uses input as keyword in its modified version of lua so you cant use it as a variable try changing ‘input’ to Input, that is with a capital I in both your local and client scripts. Also in your server side script you need to change your structuring of if statements. do it like this instead:
if Codes[Input] then -- first you need to check if the code is valid so you are checking if a index exists in the table
if Codes[Input].Used == false then
---then you do this
end
end
Also what you can do instead of structuring your code system like that is to just store a list of codes that the player already uses and a module script on the server with a list of valid codes. This will help to reduce the size of the data your are storing significantly.
I don’t think that would be the issue, I’ve tested in studio and it doesn’t seem to be recoloured by studio and stays the same regular colour as any other variable name.
local players = game:GetService("Players")
local dataStore2 = require(1936396537)
local CodeStoreName = "TwitterCodes"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function setupUserData()
local Codes = {
["YEET1"] = {Used = false, Reward = 500}
}
return Codes
end
ReplicatedStorage.TwitterCode.OnServerEvent:Connect(function(player, input)
local Codes = dataStore2(CodeStoreName, player):Get(setupUserData(), setupUserData()) --set a defualt value if there's no save
if Codes[input] and not Codes[input].Used then --if input is in codes & input is false then
--do your code stuff here
end
end)