I used this script for my minigames
minigames = {}
for i,v in pairs (game.Lighting:GetChildren()) do
if v:IsA("Model") then
table.insert(minigames,v)
end
end
function playerAdded(player)
local Id = Instance.new("IntValue")
Id.Name = "leaderstats"
local points = Instance.new("IntValue",Id)
points.Name = "Money"
Id.Parent = player
end
function playerWon(player,points)
local m = Instance.new("Message", workspace)
m.Text = player.Name.." has won the minigame!"
local money = player.leaderstats.Money
money.Value = money.Value + points
wait(3)
m:Destroy()
end
function chooseMinigame()
return minigames[math.random(1,#minigames)]
end
function getParticipants()
return game.Players:GetPlayers()
end
function teleportPlayers(players,position)
for _,v in pairs(players) do
if v.Character then
v.Character:MoveTo(position)
end
end
end
function loadMinigame(mg)
local m = mg:clone()
m.Parent = workspace
return m
end
function runMinigame(m)
if m:FindFirstChild("pos") then
teleportPlayers(getParticipants(),m.pos.Position)
end
while m.time.Value > 0 do
--TODO: check to see if game is running
if m.winner.Value then
playerWon(m.winner.Value,m.points.Value)
break
end
wait()
end
end
function endMinigame(m)
m:Destroy()
end
Game:GetService("Players").PlayerAdded:connect(playerAdded)
while wait() do
wait(10)
local m = chooseMinigame()
local loaded = loadMinigame(m)
runMinigame(loaded)
endMinigame(loaded)
print(3)
end
The problem is, when you touch a brick, it doesn't award points like it should. I do get something in output.
Workspace.main:21: attempt to perform arithmetic on global 'points' (a nil value) 16:26:23.738 - Stack Begin 16:26:23.739 - Script 'Workspace.main', Line 21 - global playerWon 16:26:23.739 - Script 'Workspace.main', Line 56 - global runMinigame 16:26:23.740 - Script 'Workspace.main', Line 74 16:26:23.740 - Stack End
And whenever I touched the brick, the whole script breaks. Someone please help.
