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
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.
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
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)