Hi, so I got the error attempt to index nil with 'Value`
on a line with the code:
if CoinsCollected.Value > MostCoins.Value then
These values are both Number values and it works once but not twice.
Hi, so I got the error attempt to index nil with 'Value`
on a line with the code:
if CoinsCollected.Value > MostCoins.Value then
These values are both Number values and it works once but not twice.
Could we see the full script? It’ll help us identity the problem much easier
This means either CoinsCollected
or MostCoins
is nil. This can not be solved without the rest of your code.
At line 48
--Variables--
local Honk = workspace.Sounds.Honk
local Text = game.ReplicatedStorage.Values.TimerText
local Winner = Text.Parent.Winner
local Time = 30
local MostCoins = Winner.Parent.MostCoins
local TieValue = Winner.Parent.TieValue
local Winners = {}
local InRound = MostCoins.Parent.InRound
--Round Script--
while true do
InRound.Value = false
while true do
--Changes the Text to This: --
Text.Value = "Intermission: "..Time.." Seconds left!"
--Checks if round ended or not--
if Time == 0 then
Text.Value = "Starting Round..."
wait(5)
Time = 90
break
else
if Time < 11 then
workspace.Sounds.Tick:Play()
end
wait(1)
Time = Time-1
end
end
Text.Value = "Round Starting in: 3"
Honk:Play()
wait(1)
Text.Value = "Round Starting in: 2"
Honk:Play()
wait(1)
Text.Value = "Round Starting in: 1"
Honk:Play()
wait(1)
Honk.Parent.HighPichedHonk:Play()
InRound.Value = true
while wait(1) do
--same as the intermission script but different--
Text.Value = "Round: "..Time.." Seconds left!"
if Time == 0 then
local Players = game.Players:GetChildren()
for _,v in pairs(Players) do
local CoinsCollected = v.CoinsCollected
if CoinsCollected.Value > MostCoins.Value then
table.clear(Winners)
Winner.Value = v.Name
TieValue.Value = 1
Winners[1] = v.Name
MostCoins.Value = CoinsCollected.Value
elseif CoinsCollected.Value == MostCoins.Value then
Winner.Value = Winner.Value..", "..v.Name
TieValue.Value += 1
Winners[TieValue.Value] = v.Name
end
end
if Winner.Value == "" then
Text.Value = "Round ended! Nobody won!"
elseif TieValue.Value < 1 then
Text.Value = "Round ended! "..Winner.Value.." has won in a "..TieValue.Value.." way tie with "..MostCoins.Value.." coins!"
else
Text.Value = "Round ended! "..Winner.Value.." has won with "..MostCoins.Value.." coins!"
end
TieValue.Value = 0
MostCoins = 1
for _,v in pairs(Winners) do
local Player = game.Players:FindFirstChild(v)
Player.leaderstats.Wins.Value += 1
end
game.ReplicatedStorage.RemoteEvents.RoundEnded:FireAllClients()
wait(5)
Time = 30
break
else
if Time < 11 then
workspace.Sounds.Tick:Play()
end
Time = Time-1
end
end
end
local CoinsCollected = v:WaitForChild("CoinsCollected")
It is the MostCoins variable. –
Could you explain a little more?
What is the Class of Winner, or winner? -
The class of winner is a StringValue
Personally, I am not a fan of this style of coding but you would need to create and instance or clone an instance of a StringValue to place inside the player which I assume would be the parent. Since I assume you want the Winner to be a player, the player does not exist; the Winner does not exist and is therefore nil.
Edit: I misunderstood your code. You have the winner stored in the ReplicatedStorage using a String value.
I found the problem and fixed it
What was the problem ??? `````
Apparently this was not giving off any errors