Hello, I have this Script and it is in a Tool. The Tool has a StringValue named Crafter and the Script is supposed to Read that StringValue’s Value which is a Username, and it is supposed to Check that StringValue’s Value and Find the Player by the Username and find the Leaderstats.
I do not get an Error, but it doesn’t work.
By the way I do get a Infinite Yield Warning.
Infinite yield possible on ‘Players:WaitForChild(“”)’ - Studio
Here is the Code:
local tool = script.Parent
local ownerCrafter = tool.Crafter
local addEvent = tool:FindFirstChild("addXP")
-- get the players username from the ownerCrafter stringValue's value which is their username
local player = game:GetService("Players"):WaitForChild(ownerCrafter.Value)
print(player.Name)
local leaderstats = player:FindFirstChild("leaderstats")
local XP = leaderstats and leaderstats:FindFirstChild("XP")
local function addXP()
if XP then
XP.Value = XP.Value + 1
print("value added")
end
end
addEvent.OnServerEvent:Connect(addXP)