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

How can i make so that when a part is touched it changes the Value of a StringValue ?

Hello i was wondering how can i make so that when a part is touched it changes the Value of a StringValue, and why does my script doesn't work ? Thank you and happy new year ! :D

local CO8 = script.Parent.Parent.CurrentOwner8.Value

script.Parent.Parent.PartFire.Touched:Connect(function(P)
	local PL = game.Players:GetPlayerFromCharacter(P.Parent)
	
	if PL then
		CO8 = PL
	end
end)

1 answer

Okay so, there are several issues within your script.

The first one is, you cannot place numbers when setting the variable name, so instead of CO8 you should select another name.

Second one, When you try to index a name that has characters that could be confused with other things, such as numbers or symbols, they should be written inside a string box, like this:

local Variable = script.Parent["Variable1"] -- It has a number, so if we had written it as normal the script would error.

Third thing, you're trying to change the value of the stringvalue, but in the variable, you're setting the value of the stringvalue, but not the stringvalue itself. Doing that, your stringvalue will never be updated, as you're updating the local variable, but not the stringvalue. Fixing that is easy, just remove the .Value in the local variable:

local StringValue = script.Parent.StringValue -- not script.Parent.StringValue.Value

Fourth thing, When you get the local variable and set their value to the player, it will error again. The reason is easy, you're trying to set a Player object into a StringValue object, which can't be concatenated. To do that, you need the Player's name, which is again easy to get:

local Variable = Player.Name -- Here we're getting the Player's name, not the Player itself.

With these things I told you, you might be able how to fix your errors and maybe you can learn more related to Lua Variables. Hope this helped!

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