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

need help with a random name -> dialogue script (anyone wanna help?)

need help,

local speechName = game.StarterGui.ScreenGui.guiSpeech
local DataStore = game:GetService("DataStoreService")
local DataName = DataStore:GetDataStore("SaveNames")

local RandomNames = {"Charlie","Georgia","Sam","Kira","Poke","Robin","Josh","Logan","Luca","Wade","Matthew","Caleb","Jayden","Max","Harvey",}

game.Players.PlayerAdded:Connect(function(Player)
local RandName = RandomNames[math.random(#RandomNames)]
local PlrName = Instance.new("StringValue", Player)
    PlrName.Name = "PlrName"
    PlrName.Value = DataName:GetAsync(Player.UserId) or RandName
    DataName:SetAsync(Player.UserId, PlrName.Value)
end)
game.Players.PlayerRemoving:Connect(function(player)
    DataName:SetAsync(player.UserId, player.PlrName.Value)
end)

if RandomNames == "Sam" then
    wait(13)
    speechName.Text = "S"
    wait(0.6)
    speechName.Text = "Sa"
    wait(0.6)
    speechName.Text = "Sam"
    wait(0.6)
    speechName.Text = "Sam!"
end

this script will give the player a random name and through datastore it will save that name. that is all fine but at the bottom there is a if statement that will change text in a text label to the players name. this does. not work. anyone wanna help with a fix?

2 comments

0

Your changing the StarterGui's GUI, NOT the player's

1 answer

This should work. Comment if there are bugs

local DataStore = game:GetService("DataStoreService")
local DataName = DataStore:GetDataStore("SaveNames")

local RandomNames = {"Charlie","Georgia","Sam","Kira","Poke","Robin","Josh","Logan","Luca","Wade","Matthew","Caleb","Jayden","Max","Harvey",}

game.Players.PlayerAdded:Connect(function(Player)
local RandName = RandomNames[math.random(#RandomNames)]
local PlrName = Instance.new("StringValue", Player)
	PlrName.Name = "PlrName"
	PlrName.Value = DataName:GetAsync(Player.UserId) or RandName
	DataName:SetAsync(Player.UserId, PlrName.Value)
	
	local speechName = Player.PlayerGui.ScreenGui.guiSpeech
	
	local function say()
		wait(13)
		for i = 1,PlrName.Value:len() do
			speechName = speechName..PlrName.Value:sub(i,i)
			wait(0.6)
		end
		wait(0.6)
		speechName = speechName.."!"
	end
	say()
end)
game.Players.PlayerRemoving:Connect(function(player)
	DataName:SetAsync(player.UserId, player.PlrName.Value)
end)

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