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

How come the value wont get changed and I wont get warned because of it?

I'm trying to replace a value inside a folder that inside a folder inside the player GUI, but it won't change I have a warn() in place for that but it won't warn me. Whats happening. P.s. the script is in a local script inside a folder inside the playergui.

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local workSpace = game:GetService("Workspace")

local Buttons = script.Parent.Parent.MainGui.Buttons
local ValuesFolder = script.Parent.Parent.ValuesFolder

if Player.Character then
	if ReplicatedStorage:FindFirstChild(Player.Name.."Country") then
		local PlayerCountry = ReplicatedStorage:FindFirstChild(Player.Name.."Country")
		if ValuesFolder.Country.Value == "" then
			ValuesFolder.Country.Value = PlayerCountry.Value --doesn't work
			if PlayerCountry.Value == "" then
				warn("Did not work as intended") --does not print
			end
		end
	end
elseif Player.Character == nil then
	if ReplicatedStorage:FindFirstChild(Player.Name.."Country") then
		local PlayerCountry = ReplicatedStorage:FindFirstChild(Player.Name.."Country")
		if ValuesFolder.Country.Value == "" then
			ValuesFolder.Country.Value = PlayerCountry.Value --doesn't work
			if PlayerCountry.Value == "" then
				warn("Did not work as intended") --does not print
			end
		end
	elseif ReplicatedStorage:FindFirstChild(Player.Name.."Country") == nil then
		local PlayerCountry = ValuesFolder.Country:Clone()
		PlayerCountry.Name = Player.Name.."Country"
		PlayerCountry.Parent = ReplicatedStorage.PlayerCountrys --works
	end
end

1 comment

0

Is there an instance in the ReplicatedStorage that's named plrnameCountry? And why is it located in the ReplicatedStorage instead of PlayerCountrys as specified in the last block of code?

2 answers

✓ Accepted answer

Made a new variable since in line 36, it specified "PlayerCountries" and in the last code (your code), it was specified the cloned instance to be the parent of "PlayerCountrys" at line 30 (Just fixing a bit of spelling in mine)

I see no errors other than that. It should work just fine even in your script; it just means the script couldn't find the instance and then skips that line of code, then the next executes.

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local workSpace = game:GetService("Workspace")

local Buttons = script.Parent.Parent.MainGui.Buttons

local ValuesFolder = script.Parent.Parent.ValuesFolder
local PlayerCountries = ReplicatedStorage.PlayerCountries

if Player.Character then
	if PlayerCountries:FindFirstChild(Player.Name.."Country") then
		local PlayerCountry = PlayerCountries:FindFirstChild(Player.Name.."Country")
		if ValuesFolder.Country.Value == "" then
			ValuesFolder.Country.Value = PlayerCountry.Value
			if PlayerCountry.Value == "" then
				warn("Did not work as intended")
			end
		end
	elseif not PlayerCountries:FindFirstChild(Player.Name.."Country") then -- Dunno if you need this one, you can delete this elseif statements if you'd like.
		local PlayerCountry = ValuesFolder.Country:Clone()
		PlayerCountry.Name = Player.Name.."Country"
		PlayerCountry.Parent = PlayerCountries
	end
elseif Player.Character == nil then
	if PlayerCountries:FindFirstChild(Player.Name.."Country") then
		local PlayerCountry = PlayerCountries:FindFirstChild(Player.Name.."Country")
		if ValuesFolder.Country.Value == "" then
			ValuesFolder.Country.Value = PlayerCountry.Value
			if PlayerCountry.Value == "" then
				warn("Did not work as intended")
			end
		end
	elseif not PlayerCountries:FindFirstChild(Player.Name.."Country") then
		local PlayerCountry = ValuesFolder.Country:Clone()
		PlayerCountry.Name = Player.Name.."Country"
		PlayerCountry.Parent = PlayerCountries
	end
end

But if you're trying to execute the script after the instance has been added, then you can wrap it up in a function and then call the function. Or you can wrap it up using coroutine.

DevHub: coroutine

DevForum: What is Coroutine? by Mysterious_Myth11

DevForum: Coroutines - When and how to use them by ReturnedTrue

Youtube: Advanced Roblox Scripting Tutorial #33 - Coroutine by TheDevKing

Bit of advice: you can use "not" in an if statement

local bool = false
local nonExistent = nil
local Frame = script.Parent

if not bool then
	print("false") -- Will print
else
	print("this wont print because bool is false") -- Won't print
end


if nonExistent then
	print("This won't print because it is nil")
else
	print("This will print because it is nil")
end

Frame.Visible = not Frame.Visible
-- This turns the frame visibility boolean to the opposite boolean, e.g: true to false, false to true

3 comments

0

Edited to add in more links

0

Thank you! I never noticed. I thought my script just didn't work for so long.

0

I'll also be taking you suggestions into use.

The value isn't set to "" bye default its set to nil so try something like this:

 if ValuesFolder.Country.Value == nil then
	            ValuesFolder.Country.Value = PlayerCountry.Value
	            if PlayerCountry.Value == nil then
	                warn("Did not work as intended")
	            end

and if I missed anything else that was set to "" try setting it to nil.

3 comments

0

'nil' just means empty or nonexistent

0

this is assuming its not a int or number value btw

0

Judging by the result I got when I tried to print the value of an empty string/number/intvalue, it all prints either a blank space or 0, but nothing printed nil.

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