There is currently a bug in a game I'm developing for which causes a player not to be able to spawn into the game, to counter that, I'm trying to give a player spins if their magic is an empty string and have 0 spins. What I've tried is as follows:
game.Players.PlayerAdded:connect(function(Player)
local magic = game.ReplicatedStorage:FindFirstChild(Player.Name.."Element").Value
local spins = Player.leaderstats1.Tries.Value
if magic == "" and spins == 0 then
spins = spins + 5
print("Gave Spins")
end
end)
The values for both magic and spins are correct since I've used it in other parts of the game, but what I'd like to know is why this isn't working.
If you do need it, here is the script for the stats:
--Datastore is where the game saves and stores your data, this script was made by SAGETHEGAMER
local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore") --Call "GameStore" whatever you like
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats1"
leaderstats.Parent = player
local Level = Instance.new("IntValue") --Change points to whatever you want, unless you want to keep it
Level.Name = "Level" --Name of the Points, or whatever name you changed it to
Level.Parent = leaderstats
local reallev = Instance.new("IntValue")
reallev.Name = player.Name.."Level"
reallev.Parent = game.ReplicatedStorage
local realelm = Instance.new("StringValue")
realelm.Name = player.Name.."Element"
realelm.Parent = game.ReplicatedStorage
local Cash = Instance.new("IntValue")
Cash.Name = "Gems"
Cash.Parent = leaderstats
local XP = Instance.new("IntValue")
XP.Name = "XP"
XP.Parent = leaderstats
local Clicks = Instance.new("IntValue")
Clicks.Name = "Click"
Clicks.Parent = leaderstats
local Tries = Instance.new("IntValue")
Tries.Name = "Tries"
Tries.Parent = leaderstats
local Element = Instance.new("StringValue")
Element.Name = "Element"
Element.Parent = leaderstats
local check = require(script.Ranking)
check.checkRank(player,2904421)
local Element2 = Instance.new("StringValue")
Element2.Name = "Element2"
Element2.Parent = leaderstats
local MSz = Instance.new("BoolValue", player)
MSz.Parent = player
MSz.Value = false
MSz.Name = "Muted"
local FakeName = Instance.new("StringValue", game.ReplicatedStorage)
FakeName.Parent = game.ReplicatedStorage
FakeName.Value = ""
FakeName.Name = player.Name.."FakeName"
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
Level.Value = storeditems[1]
reallev.Value = storeditems[1]
Cash.Value = storeditems[2]
XP.Value = storeditems[3]
Tries.Value = storeditems[4]
Element.Value = storeditems[5]
realelm.Value = storeditems[5]
Element2.Value = storeditems[6]
else
local items = {Level.Value, Cash.Value, XP.Value, Tries.Value, Element.Value, Element2.Value} --Change Points or Wins if you changed line 10 or 14
datastore:SetAsync(key, items)
end
Element2.Value = ""
if Level.Value == 1 or Level.Value == 0 then
if Element.Value == "" and Tries.Value < 1 and XP.Value < 1 then
Tries.Value = Tries.Value + 25
end
end
if Level.Value > 1000 then
Level.Value=100
end
if Tries.Value > 500 then
Tries.Value=500
end
if Clicks.Value > 100 then
Clicks.Value = 0
end
player.Backpack.ANTIXPLOIT.Disabled = false
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.leaderstats1.Level.Value, player.leaderstats1.Gems.Value, player.leaderstats1.XP.Value, player.leaderstats1.Tries.Value, player.leaderstats1.Element.Value, player.leaderstats1.Element2.Value} --Change Points or Wins if you changed line 10 or 14
local key = "user-" .. player.userId
for _,v in pairs(game.ReplicatedStorage:GetChildren()) do
if v.Name == player.Name.."Level" and v.Name == player.Name.."Element" then
v:Remove()
end
end
datastore:SetAsync(key, items)
end)

4 comments
Line 51, you've already parent MSz to player.
In the first script, On line 4, try doing: "local spins = Player:WaitForChild("leaderstats1").Tries.Value"
In first script, in line 5 & 6, well line 6, why don't you just write: "spins.Value = 5" since you know that they have 0 spins.
On line 2 & 3, don't put ".Value", and on line 5 put: "if magic.Value == "" and spins.Value == 0 then", on line 6 put: "spins.Value = 5"