Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

WaitForChild() not detecting player name when the function is called?

I am attempting to replicate a particle into the player torso, and into a model, named the same as the player in the replicated storage through a shop button. Replicating into the player works fine, but :WaitForChild(plr.Name) is not, with nothing happening after that point.

local plr = game.Players.LocalPlayer
local PartOwned = plr.Part1Owned
local RS = game:GetService('ReplicatedStorage')
local Particle = game.ReplicatedStorage:WaitForChild("PurpleSparkles") -- particle

if  PartOwned == true then
	script.Parent.Visible = false
	script.Parent.Parent.Equip.Visible = true
end
script.Parent.MouseButton1Click:Connect(function(player)
	local stats = plr:WaitForChild("leaderstats")
	local torso = plr.Character:WaitForChild("UpperTorso")
	if stats.Gems.Value >= 25 then
		stats.Gems.Value = stats.Gems.Value  - 25
		local SparkleClone2 = Particle:Clone()
		SparkleClone2.Parent = plr.Character:WaitForChild("UpperTorso") -- replicating
		local SparkleClone = Particle:Clone()
		SparkleClone.Parent = game.ReplicatedStorage:WaitForChild("plr.Name") -- where the script fails, in detecting the model named the same as them
		script.Parent.Visible = false
		script.Parent.Parent.Unequip.Visible = true
		PartOwned.Value = true
	end
end)

I can't find why the script is not detecting the model. I have checked, and it does match the same name as the player when they join.

1 answer

✓ Accepted answer

Hello, RandomMildChicken!

local plr = game.Players.LocalPlayer
local PartOwned = plr.Part1Owned
local RS = game:GetService('ReplicatedStorage')
local Particle = game.ReplicatedStorage:WaitForChild("PurpleSparkles") -- particle

if  PartOwned == true then
    script.Parent.Visible = false
    script.Parent.Parent.Equip.Visible = true
end
script.Parent.MouseButton1Click:Connect(function(player)
    local stats = plr:WaitForChild("leaderstats")
    local torso = plr.Character:WaitForChild("UpperTorso")
    if stats.Gems.Value >= 25 then
        stats.Gems.Value = stats.Gems.Value  - 25
        local SparkleClone2 = Particle:Clone()
        SparkleClone2.Parent = plr.Character:WaitForChild("UpperTorso") -- replicating
        local SparkleClone = Particle:Clone()
        SparkleClone.Parent = game.ReplicatedStorage:WaitForChild(plr.Name) -- Removed the ",  they were making the 'plr.Name' be considered as a string, not a variable
        script.Parent.Visible = false
        script.Parent.Parent.Unequip.Visible = true
        PartOwned.Value = true
    end
end)

If you need more help add me as friend on roblox

Good Luck with your games

1 comment

0

lol

This discussion is preserved as it was. New answers, comments, and votes are closed.