I'm currently working on a spawn system for my game and the tools are dependent on a string value, but for some reason even tho the string value does not equal the required string it keeps giving the player the wrong tool What Is the problem here. I don't even get errors just a blank output. (kinda I still get prints and stuff.)
Script
function onSpawnPlayer(Player)
wait(.1)
local MainPlayerGui = game.StarterGui["MainGui"]:Clone()
if not Player.PlayerGui:FindFirstChild("MainGui") then
MainPlayerGui.Parent = Player.PlayerGui
else
Player.PlayerGui:FindFirstChild("MainGui"):Destroy()
MainPlayerGui.Parent = Player.PlayerGui
end
ReplicatedStorage.Events.SpawnEvent.OnServerEvent:Connect(function(Player) --Everthing beyond this line does not work as intended.
local Country = Player.PlayerGui.MainGui.ValuesFolder.Country or ReplicatedStorage.PlayerCountries[Player.Name.."Country"]
local Class = Player.PlayerGui.MainGui.ValuesFolder.Class or ReplicatedStorage.PlayerCountries.PlayerClasses[Player.Name.."Class"]
MainPlayerGui:Destroy()
Player:LoadCharacter()
if Country.Value == "Britain" then
if Class.Value == "RifleMan" then
local RifleManTool = TeamTools.Primary["Smle-MK3"]:Clone()
RifleManTool.Parent = Player.Backpack
elseif Class.Value == "Sapper" then
local SapperTool = TeamTools.Primary["Lewis Gun"]:Clone()
SapperTool.Parent = Player.Backpack
end
elseif Country.Value == "France" then
if Class.Value == "RifleMan" then
local RifleManTool = TeamTools.Primary["Berthier-07"]:Clone()
RifleManTool.Parent = Player.Backpack
end
elseif Country.Value == "America" then
if Class.Value == "RifleMan" then
local RifleManTool = TeamTools.Primary["Springfield M1903"]:Clone()
RifleManTool.Parent = Player.Backpack
elseif Class.Value == "Sapper" then
local SapperTool = TeamTools.Primary["Lewis Gun"]:Clone()
SapperTool.Parent = Player.Backpack
end
end
if Country.Value == "Germany" then
if Class.Value == "RifleMan" then
local RifleManTool = TeamTools.Primary["Gewehr-98"]:Clone()
RifleManTool.Parent = Player.Backpack
end
elseif Country.Value == "Austria-Hungary" then
if Class.Value == "RifleMan" then
local RifleManTool = TeamTools.Primary["Gewehr-88"]:Clone()
RifleManTool.Parent = Player.Backpack
end
elseif Country.Value == "Ottoman Empire" then
if Class.Value == "RifleMan" then
local RifleManTool = TeamTools.Primary["Turkish Mauser"]:Clone()
RifleManTool.Parent = Player.Backpack
end
end
end)
function onPlayerDeath(Character)
print("Died")
if Player.PlayerGui:FindFirstChild("StatusUI") then
Player.PlayerGui:FindFirstChild("StatusUI"):Destroy()
end
Player.Backpack:ClearAllChildren()
wait(5)
Events.RestartEvent:FireClient(Player)
Character:Destroy()
end
end
What I suspected
When I first encountered this I believed it was due to the fact that the script didn't have enough time to get the correct string so it got the default string, but when I attempted to fix that with a wait() it had no effect. I've encountered stuff like this before and most of the time it would be due to a lack of time for the values to load properly, but that seems to not be the case.
If you would like to resolve it over discord
My Discord used is "VincenttheBaguette1#1253".

4 comments
Have you checked if the Class.Value and Country.Value is correct? I suspect the issue is the variable or the StringValue.
If your talking about if they meet with the requirements then yes I have and it matches correctly I probably should have stated that -_-
I'm sorry if I miss what you're saying, but is both Values conflicting? Like the Class in ReplicatedStorage is RifleMan but the class in the MainGui is Sapper?
I was just able to fix it. I'll make an answer in a min.