Hello, I have a leaderstat called “Material”. It’s variable name is “PartMaterial”. I am getting an infinite yield for “PartMaterial” because it is called “Material” but there is no reason for it to be called “PartMaterial”. Can anybody help?
Show the code, otherwise no one can really help
the infinite yield msg means that the object name you are trying to wait for does not exist.
I don’t know where the error is coming from. Here is my leaderstats and main use of them:
local DataStoreService = game:GetService("DataStoreService")
local PartsStore = DataStoreService:GetDataStore("playerPartsSave")
--Create Leaderstats
game:GetService("Players").PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player) --Leaderstats
leaderstats.Name = "leaderstats"
local Parts = Instance.new("IntValue", leaderstats) --Parts
Parts.Name = "Parts"
local PartColor = Instance.new("StringValue", leaderstats) --PartColor
PartColor.Name = "Color"
PartColor.Value = "White"
local PartMaterial = Instance.new("StringValue", leaderstats)
PartMaterial.Name = "Material"
PartMaterial.Value = "Plastic"
--Load Data
local playerUserID = ("Player_" .. player.UserId)
local success, errorMessage = pcall(function()
data = PartsStore:GetAsync(playerUserID)
end)
if success then
print("Player Data Loaded")
Parts.Value = data
print(data)
else
print("Player's data wen't no")
end
end)
--Add Parts RemoteEvent
game:GetService("ReplicatedStorage").plusPart.OnServerEvent:Connect(function(player, multiplier)
player:WaitForChild("leaderstats"):WaitForChild("Parts").Value += multiplier
end)
--Save Data
game.Players.PlayerRemoving:Connect(function(player)
local playerUserID = ("Player_" .. player.UserId)
local data = player.leaderstats.Parts.Value
local success, errorMessage = pcall(function()
PartsStore:SetAsync(playerUserID, player.leaderstats.Parts.Value)
end)
if success then
print("Data Saved")
else
print("Data Fricked Up")
end
end)
function onShutDown()
task.wait(4)
end
game:BindToClose(onShutDown)
local player = game.Players.LocalPlayer
player:WaitForChild("leaderstats"):WaitForChild("PartMaterial")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
workspace.SpawnPart.Button.ClickDetector.createPart.OnClientEvent:Connect(function()
for i, v in pairs(ReplicatedStorage:GetChildren()) do
if v.Name == player.leaderstats.Color.Value then
materialMultiplier = "notloadedyet"
part = v:Clone()
break
end
end
function SetPartMaterial()
local material = player.leaderstats.Material
if material == "Plastic" then
part.Material = Enum.Material.Plastic
materialMultiplier = 1
elseif material == "SmoothPlastic" then
part.Material = Enum.Material.SmoothPlastic
materialMultiplier = 5
elseif material == "Slate" then
part.Material = Enum.Material.Slate
materialMultiplier = 30
elseif material == "Marble" then
part.Material = Enum.Material.Marble
materialMultiplier = 75
elseif material == "Pebble" then
part.Material = Enum.Material.Pebble
materialMultiplier = 250
elseif material == "WoodPlanks" then
part.Material = Enum.Material.WoodPlanks
materialMultiplier = 500
elseif material == "Cobblestone" then
part.Material = Enum.Material.Cobblestone
materialMultiplier = 1250
elseif material == "Brick" then
part.Material = Enum.Material.Brick
materialMultiplier = 5000
elseif material == "Asphalt" then
part.Material = Enum.Material.Asphalt
materialMultiplier = 15000
elseif material == "Neon" then
part.Material = Enum.Material.Neon
materialMultiplier = 35000
elseif material == "DiamondPlate" then
part.Material = Enum.Material.DiamondPlate
materialMultiplier = 100000
end
end
SetPartMaterial()
local multiplier = materialMultiplier * part:WaitForChild("PartMultiplier").Value
game.ReplicatedStorage.plusPart:FireServer(multiplier)
part.Owner.Value = player.Name
part.Parent = workspace
part.Position = Vector3.new(math.random(-21, 23.5), 17, math.random(-41.25, -24))
wait(2)
part:Destroy()
end)
this is where its occuring, change it to:
player:WaitForChild("leaderstats"):WaitForChild("Material")