Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a randomly generated number for a card tool?

How would I make a credit card tool, when you hold it, it opens a UI, then the UI has a randomly generated number as the card number. How do I randomly generate a number per each person and save that number for each game?

My current scripts are as follows:

https://gyazo.com/319be8392102647b53396d7bcb65cfe2 https://gyazo.com/0471345f1094227aca81e991696b552f https://gyazo.com/42ab2650d1132241290206567e1a30fd

LocalScript:


script.Parent.Equipped:Connect(function()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
 
createPartEvent:FireServer()

local RandomFirstDigit = math.random(1,9)
local RandomSecondDigit = math.random(1,9)
local RandomThirdDigit = math.random(1,9)


end)

Script:

-- Script
 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
 
local function onCreatePartFired(player)
     game.StarterGui.ScreenGui.Frame.Visible = true
end
 
createPartEvent.OnServerEvent:Connect(onCreatePartFired)

3 comments

0

Why are you using a RemoteEvent to enable a GUI? Since you're using a LocalScript you can enable the GUI.

0

Also keep in mind the StarterGui is not where the players current UI's are stored, they are stored in the player under Players. The StarterGui is used to copy its contents (GUI's) to the player so they receive the GUI's upon entering the game or re-spawning.

0

Lol im so confused by this. You used a remote event that wasnt needed, and then made variables for the "credit card number" then never called them?

1 answer

You should have three text labels in the screen gui. Number1,Number2 and Number3 then in the local script try this

local number1 = game.StarterGui.ScreenGui.Frame.Number1
local number2 = game.StarterGui.ScreenGui.Frame.Number2
local number3 = game.StarterGui.ScreenGui.Frame.Number3
local ui = number1.Parent.Parent
script.Parent.Equipped:Connect(function()
ui.Enabled = true
local one = math.random(1,9)
local two = math.random(1,9)
local three = math.random(1,9)

number1.Text = one
number2.Text = two
number3.Text = three
end)
script.Parent.Unequipped:Connect(function()
ui.Enabled = false
end)

And that should work. You dont need the normal script or the events or whatever.

This discussion is preserved as it was. New answers, comments, and votes are closed.