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

Changing a StringValue?

I have put a Stringvalue in the player, called : QuestProgress The String's base value is: None I want so that when a player touches a part the string value changes, but struggled to do it on my own, probably because i'm acting like it is a IntValue. The script in the part is:

script.Parent.Touched:connect(function(player)
	    print (player.Parent.Name) --This would print the name of the person who touched the brick
	    local Player_name = player.Parent.Name
	    local Quest=script.Parent
	    Quest:remove()  -- Haven't tested the remove part, because the script wasn't working without it, anyway.
	    game.Players[Player_name].CurrentQuest.Value=game.Players[Player_name].CurrentQuest.Value.Finding Apples -- I think this is the problem 
	end)

I have tried this for the last line too:

game.Players[Player_name].CurrentQuest.Value=game.Players[Player_name].CurrentQuest.Value."Finding Apples"

To no prevail. Thanks.

1 answer

✓ Accepted answer

Try this line in place of 6 --

game.Players:GetPlayerFromCharacter(player).CurrentQuest.Value = "Apples"

Assuming that's what you're attempting to do, it should work.

This is because in a touched function, it returns the Character player (game.Workspace), not the game.Players player. By using Players:GetPlayerFromCharacter(player), it'll then reformat the game.Workspace character into the game.Players player.

And, when setting string values (assuming you were trying to just do this), all you need is the text you want to set it to in "".

(Excuse anything that might seem obvious in explanation -- I'd rather over explain than under explain)

EDIT After examining the issue more thoroughly, it seems that the way you're setting your string is the true issue.

5 comments

0

That part would still work in his original code. But your code is still correct, just more efficient.

0

Hmm, that is true. I'm not used to the player being called in that manner.

0

Got it, thanks, my only problem is that the part deletes itself as soon as I play solo, if I remove the 3rd and 4th lines, it works, any suggestions?

0

Would that not be because of "Quest:remove()"? Or are you saying that it just deletes itself as soon as you join the game without touching the button? (in solo)

0

Yeah, as soon as I join without touching.

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