Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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)
0
Why are you using a RemoteEvent to enable a GUI? Since you're using a LocalScript you can enable the GUI. User#24403 69 — 5y
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. ForeverBrown 356 — 5y
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? DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question