I am making an RPG, and I am making a race menu that only becomes visible when you are a new player, and otherwise will not show. The buttons worked fine before I set up my datastore to save all stats, maybe that has something to do with it?
It shows no error in output and no reason to not work.
When a button is clicked:
script.Parent.MouseButton1Click:Connect(function()
local Player = game.Players.LocalPlayer
game.ReplicatedStorage.RaceChoosingEvents.BeastChosen:FireServer(Player)
end)
The receiving end of the event:
game.ReplicatedStorage.RaceChoosingEvents.BeastChosen.OnServerEvent:Connect(function(Player)
Player.Backpack.ServerTraits.Statistics.Race.Value = "Beast"
Player:LoadCharacter()
end)
The datastore:
repeat wait(2) until game.Loaded
local datastore = game:GetService("DataStoreService"):GetDataStore("Race")
game.Players.PlayerAdded:connect(function(player)
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
player.Backpack.ServerTraits.Statistics.Exp.Value = storeditems[1]
player.Backpack.ServerTraits.Statistics.Level.Value = storeditems[2]
player.Backpack.ServerTraits.Statistics.Tranquility.Value = storeditems[3]
player.Backpack.ServerTraits.Statistics.Strength.Value = storeditems[4]
player.Backpack.ServerTraits.Statistics.MaxExp.Value = storeditems[5]
player.Backpack.ServerTraits.Statistics.Speed.Value = storeditems[6]
player.Backpack.ServerTraits.Statistics.Stamina.Value = storeditems[7]
player.Backpack.ServerTraits.Statistics.Race.Value = storeditems[8]
else
local items = {player.Backpack.ServerTraits.Statistics.Exp.Value, player.Backpack.ServerTraits.Statistics.Level.Value, player.Backpack.ServerTraits.Statistics.Tranquility.Value, player.Backpack.ServerTraits.Statistics.Strength.Value, player.Backpack.ServerTraits.Statistics.MaxExp.Value, player.Backpack.ServerTraits.Statistics.Speed.Value, player.Backpack.ServerTraits.Statistics.Stamina.Value, player.Backpack.ServerTraits.Statistics.Race.Value}
datastore:SetAsync(key, items)
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.Backpack.ServerTraits.Statistics.Exp.Value, player.Backpack.ServerTraits.Statistics.Level.Value, player.Backpack.ServerTraits.Statistics.Tranquility.Value, player.Backpack.ServerTraits.Statistics.Strength.Value, player.Backpack.ServerTraits.Statistics.MaxExp.Value, player.Backpack.ServerTraits.Statistics.Speed.Value, player.Backpack.ServerTraits.Statistics.Stamina.Value, player.Backpack.ServerTraits.Statistics.Race.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
end)
And the IfPlayerIsNew script:
game.Players.PlayerAdded:Connect(function(plr)
repeat wait(2) until game.Loaded
if plr.Backpack.ServerTraits.Statistics.Race == "Human" then
local tab = game.StarterGui.MainMenu:GetChildren()
for i,v in pairs(tab) do
v.Visible = false
end
elseif plr.Backpack.ServerTraits.Statistics.Race == "Elvic" then
local tab = game.StarterGui.MainMenu:GetChildren()
for i,v in pairs(tab) do
v.Visible = false
end
elseif plr.Backpack.ServerTraits.Statistics.Race == "Beast" then
local tab = game.StarterGui.MainMenu:GetChildren()
for i,v in pairs(tab) do
v.Visible = false
end
else
local tab = game.StarterGui.MainMenu:GetChildren()
for i,v in pairs(tab) do
v.Visible = true
end
end
end)
