Hello. I’m trying to make a script that counts down, chooses a random number, checks the player backpack for a tool that has a TextLabel inside of it and then reads the text. Issue is I don’t really know how to path my way into the backpack since I’m inside of a serverscript and the countdown and randomizer has to be server sided.
Here’s my code
local WinningNumber = script.Parent.SurfaceGui.WinningNumber
local RoundTimeCountDown = script.Parent.SurfaceGui.RoundTimeCountdown
local Players = game:GetService("Players")
while true do
for i = 15, 0, -1 do
RoundTimeCountDown.Text = i
task.wait(1)
if i == 0 then
local number = math.random(1,100)
WinningNumber.Text = number
i = 15
end
end
end
local Players = game:GetService("Players")
for _, Player in pairs(Players:GetPlayers())
local Backpack = Player:FindFirstChild("Backpack")
-- now you can check
end
Thank you for your answer. I added the rest of the script but something is wrong. Am I not properly pathing the card? It doesn’t print the print function I added.
local WinningNumber = script.Parent.SurfaceGui.WinningNumber
local RoundTimeCountDown = script.Parent.SurfaceGui.RoundTimeCountdown
local Players = game:GetService("Players")
while true do
for i = 15, 0, -1 do
RoundTimeCountDown.Text = i
task.wait(1)
if i == 0 then
local number = math.random(1,1)
WinningNumber.Text = number
i = 15
for _, Player in pairs(Players:GetPlayers()) do
local Backpack = Player:FindFirstChild("Backpack")
if Backpack:FindFirstChild("Lottery Card") then
local cardText = Player.Backpack:FindFirstChild("Lottery Card").LotteryCard.SurfaceGui.TextLabel
local card = Player.Backpack:FindFirstChild("Lottery Card")
if cardText.Text == number then
print("YOU WON!!!!!!!!!!!!!!")
card:Destroy()
end
end
end
end
end
end
when the tool is equipped, it goes to the character model instead. so you can do this:
local Character = Player.Character or Player.CharacterAdded:Wait()
local lotteryCard = Backpack:FindFirstChild("Lottery Card") or Character:FindFirstChild("Lottery Card")
local cardText = lotteryCard.LotteryCard.SurfaceGui.TextLabel
if cardText.Text == number then
print("YOU WON!!!!!!!!!!!!!!")
lotteryCard:Destroy()
end
oh I see, do this instead, string is not equal to a number:
local Character = Player.Character or Player.CharacterAdded:Wait()
local lotteryCard = Backpack:FindFirstChild("Lottery Card") or Character:FindFirstChild("Lottery Card")
local cardText = lotteryCard.LotteryCard.SurfaceGui.TextLabel
if tonumber(cardText.Text) == number then
print("YOU WON!!!!!!!!!!!!!!")
lotteryCard:Destroy()
end