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

Trying to make plate system everything works fine besides this, please help me?

Asked by
RootEntry 111
5 years ago

Hi,

I am a Scripter. I have a functional radio I made, and when I say CLEAR ONE [USERNAME] in this case it's iiLevelMaker, it says my plate which is COE 962 because it gets randomized.

But when my friend joins and I do CLEAR ONE prxcid, it gets the same license plate everytime.

Screenshot: http://prntscr.com/m3hyai

Script:

local DSService = game:GetService("DataStoreService"):GetDataStore("CoreDatabsdd84")
local letters = {'a', 'b', 'c', 'd', 'e', 'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}

game.Players.PlayerAdded:Connect(function(Player)


    local Scope = 'id-'..Player.userId

    local PlayerData = Instance.new("Folder")
    PlayerData.Parent = game:GetService("ReplicatedStorage")
    PlayerData.Name = Player.Name.."Data"

    local OnValue = Instance.new("BoolValue")
    OnValue.Parent = PlayerData
    OnValue.Value = false
    OnValue.Name = "OnValue"

    local Arrests = Instance.new("IntValue")
    Arrests.Parent = PlayerData
    Arrests.Name = "Arrests"
    Arrests.Value = 0

    local hasPermit = Instance.new("BoolValue")
    hasPermit.Parent = PlayerData
    hasPermit.Name = "hasPermit"
    hasPermit.Value = false



    local l1 = letters[math.random(#letters)]:upper()
    local l2 = letters[math.random(#letters)]:upper()
    local l3 = letters[math.random(#letters)]:upper()
    local n1 = math.random(0,9)
    local n2 = math.random(0,9)
    local n3 = math.random(0,9)

    local Plate = Instance.new("StringValue")
    Plate.Parent = PlayerData
    Plate.Name = "Plate"
    Plate.Value = l1..l2..l3.." "..n1..n2..n3

    local GetSaved = DSService:GetAsync(Scope)
    if GetSaved then
        Arrests.Value = GetSaved[1]
        Plate.Value = GetSaved[2]
    else
        local NumbersForSaving = {Arrests.Value, Plate.Value}
        DSService:SetAsync(Scope, NumbersForSaving)
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
    local Scope = 'id-'..Player.userId
    local Savetable = {game:GetService("ReplicatedStorage"):FindFirstChild(Player.Name.."Data").Arrests.Value, game:GetService("ReplicatedStorage"):FindFirstChild(Player.Name.."Data").Plate.Value}
    DSService:SetAsync(Scope, Savetable)
end)

game.Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function(msg)
        if game:GetService("ReplicatedStorage"):FindFirstChild(Player.Name.."Data").OnValue.Value == true then
            local clearonecommand = string.sub(msg, 1, 10) == "CLEAR ONE "
            local targetPlayer = game:GetService("Players"):FindFirstChild(string.sub(msg, 11))
            if targetPlayer then
                local Channel = workspace.RadioSystem
                local ArrestCount = game:GetService("ReplicatedStorage"):FindFirstChild(Player.Name.."Data").Arrests
                local PermitBool = game:GetService("ReplicatedStorage"):FindFirstChild(Player.Name.."Data").hasPermit
                local Permit
                if PermitBool.Value == false then
                    Permit = "No"
                elseif PermitBool.Value == true then
                    Permit = "Yes"
                end
                Channel.Line1.Value = Channel.Line2.Value
                Channel.Line2.Value = Channel.Line3.Value
                Channel.Line3.Value = Channel.Line4.Value
                Channel.Line4.Value = Channel.Line5.Value
                Channel.Line5.Value = Channel.Line6.Value
                Channel.Line6.Value = Channel.Line7.Value
                Channel.Line7.Value = "Dispatch: Username: "..targetPlayer.Name..", Arrests: "..ArrestCount.Value..", Has FOID: "..Permit..", Plate: "..tostring(game:GetService("ReplicatedStorage"):FindFirstChild(Player.Name.."Data").Plate.Value)
                game:GetService("ReplicatedStorage").updateRadioClients:FireClient(Player)
            end
        end
    end)
end)
0
Only worry about when it saves and loads and the generator. RootEntry 111 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

One thing that could probably help you is the math.randomseed function.

Just add this line of code to the beginning of your script:

math.randomseed(tick())

Without the random seed the outputs of a math.random function is pretty consistent.

0
Wait dosen't that make it so you have to wait a while? RootEntry 111 — 5y
0
Nope, It just makes random values more random. Vinceberget 1420 — 5y
Ad

Answer this question