StringValue.Name doesn't work

Hi devs,

For some reason I can’t rename a string value.
I have this script here:

local weaponType = Instance.new("StringValue")
		weaponType.Parent = humanoid.Parent
		weaponType.Name = "WeaponType"
		weaponType.Value = "ClassicSword"

It will create a StringValue and change it’s Parent and Value, but it won’t change it’s name.

Can anyone help with this?

It works perfectly fine in other scripts

Its working on me, how do u know and check that it wont change the Name?

1
It adds the value to a player when they’re damaged, and the name is “Value” so it just adds lots of them

And when you run it the Name will be not changed?

Nope
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

Are you running this on the client or server, and are you viewing on the server or client

Viewing on client and running on server

The script what u made is it inside the Client or Server?

Try moving the parent line under the rest of the code.

Such as

local weaponType = Instance.new("StringValue")
		weaponType.Name = "WeaponType"
		weaponType.Value = "ClassicSword"
		weaponType.Parent = humanoid.Parent

It’s inside a serverscript.
I also have a similar value called PlayerThatDamaged which works fine right next to it

That would be the same


This is the full part of that area:

if humanoid.Parent:FindFirstChild("WeaponType") then
	humanoid.Parent:WaitForChild("WeaponType").Value = "ClassicSword"
else
	local weaponType = Instance.new("StringValue")
	weaponType.Parent = humanoid.Parent
	weaponType.Name = "WeaponType"
	weaponType.Value = "ClassicSword"
end

You already used :FindFirstChild theres no reason for you to be using :WaitForChild here, Also when using a :WaitForChild argument I advise you use a timeout value such as 5-10

This could be causing the script to yield waiting for a new child to be added named WeaponType

I thing the Problem is, the Value will not be going inside the Humanoid because, u dont need the Parent at the end, do this instead:

weaponType.Parent = humanoid

Try if this will work

It would not yield, because WaitForChild will also run, if there is already a WeaponType

He’s not trying to parent to the humanoid, he’s trying to parent to the humanoids parent. This line is fine

1 Like

This could cause a memory leak. There is no reason to use :WaitForChild after you already used :FindFirstChild on the same object

I’m trying to put it inside that character, rather than the humanoid.
The reason I’m using humanoid.Parent is that I’m modifying a script made by someone else that uses humanoid rather than the character.

Do you test it, that this can happen?

Maybe try changing the name before you reparent it? it looks like it should work.