ChildAdded isn't working

So, whenever a player presses the control key; It makes them sprint, and adds a string value named “Sprinting” to their character. I’m trying to create a script that senses that it’s been added, but when I tested it out, it failed.

plr.Character.ChildAdded:Connect(function(instance)
	print(instance.Name) -- It just prints "Value"
end)

Heres the script I used to create the string value

Instance.new("StringValue", game:GetService("Workspace")[tostring(TrueCharName)]).Name = "Sprinting"

If the second script was in a LocalScript then the value won’t replicate. You’re going to need to fire a remote event to the server to create the value.

Does the string value appear in the character at least?

It’s all within the same script

Yeah it does, it’s in a normal script as well. Not a local one

Can we see the full script? Keys can’t be bound through the server

It’s also not the issue, when they key is pressed its fired to a remote event which this script receives. Everything else runs fine, it’s just that it doesn’t sense anything about the value. It’s weird honestly, but heres the script

plr.Backpack.CharacterStats.Busy.Value = true
plr.Character.ChildAdded:Connect(function(instance)
    print(instance.Name)
end)
Instance.new("StringValue", game:GetService("Workspace")[tostring(TrueCharName)]).Name = "Sprinting"

Ok I figured out the issue, I added a wait and then printed the instance name and it worked. But it’s a temporary solution as I need it to be a fast process. Is there a way to wait for the name to be created?

Instead of using the ChildAdded approach, why don’t you execute a function after the Instance is created? Something like this:

local function f(value)
    print(value.Name)
    if value.Name == --[[ Sprinting? ]] then
        -- Sprint code goes here
    end
end
local ins = Instance.new(--[[ Parameters go here ]])
ins.Name = -- Name of the instance
f(ins)

1 Like