So, I've asked a question about this before, and after I did so, I've tried numerous methods on how to resolve this question. Not a single one had worked, maybe someone can help me. I am getting an error for rewarding the players, and removing players from a table when a player touches a part in a main script. Here's my error, it's only for rewarding:
ServerScriptService.MainScript:79: attempt to index number with 'Data'
Here's my code:
--// Variables
local status = game.ReplicatedStorage:WaitForChild("Status")
local plrsLeft = game.ReplicatedStorage:WaitForChild("Players")
local timer = game.ReplicatedStorage:WaitForChild("Timer")
local platesWeClone = game.ServerStorage:WaitForChild("Plates")
local income = 5
local gameTime = 20
local intermissionTime = 10
--// Functions
local function SetTimer(op)
local minutes = math.floor(op/60)
local seconds = math.floor(op%60)
timer.Value = (string.format("%.2i:%.2i", minutes, seconds))
end
local function SetStatus(op)
status.Value = tostring(op)
end
local function SetPlrs(NumPlrsInTable)
plrsLeft.Value = tostring(NumPlrsInTable)
end
--// Loop
while true do
for i = intermissionTime,0,-1 do
SetTimer(i)
SetStatus("Intermission.")
SetPlrs(0)
local plrs = {}
wait(1)
if i == 0 then
for i,v in pairs(game.Players:GetPlayers()) do
if v then
table.insert(plrs,v)
end
end
SetStatus("Cleaning play area.")
wait(0.5)
game.Workspace.Plates:Destroy()
SetStatus("Play area cleaned, game starting soon!")
local newPlates = platesWeClone:Clone()
newPlates.Parent = workspace
for e = 5,0,-1 do
SetTimer(e)
wait(1)
if e == 0 then
SetStatus("Teleporting players to play area, do not move.")
for i,v in pairs(game.Players:GetPlayers()) do
if v then
local character = v.Character
local spawns = game.Workspace:FindFirstChild("SpawnPoints")
local AvailableSpawns = spawns:GetChildren()
if character:FindFirstChild("HumanoidRootPart") then
character:FindFirstChild("HumanoidRootPart").Anchored = true
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawns[1].CFrame + Vector3.new(0,5,0)
table.remove(AvailableSpawns,1)
end
wait(5)
character:FindFirstChild("HumanoidRootPart").Anchored = false
for o = gameTime,0,-1 do
SetTimer(o)
SetStatus("Game in progress.")
SetPlrs(#plrs)
wait(1)
for i, v in pairs(game.Players:GetPlayers()) do
if v then
-------------- REMOVE FROM TABLE
local character = v.Character
game.Workspace.TableRemove.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit)
if table.find(plrs,player) then
table.remove(plrs,player)
end
end
end)
end
end
---------------------- end of gmae ::DDDDD
if o == 0 then
for index,name in pairs(plrs) do
status.Value = name
end
table.getn(plrs).Data.Money.Value = table.getn(plrs).Data.Money.Value + income
wait(5)
break
elseif #plrs == 0 then
status.Value = ""
end
end
end
end
end
end
end
end
end
