[SOLVED] I need help with a cmdr command using Number values

I’m not an scripter so this is one of my first scripts I’m trying to make, and the script works at 50% in this moment.

The first part where it says Spins works, because when I select the spins option it gives me the spins in the correct string, but when I select the ArtSpins, it just gives me the spins the same string of Spins

My code

return function (_, players, stat: string, value: number, Spins, ArtSpins)
	for _, player in pairs(players) do
		local character = player.Character
		if character then
		local Spins = character:WaitForChild("Spins")
			if Spins.Value ~= "none" then
				local Spin = Spins
				if Spin then
				player.Character.Spins.Value = player.Character.Spins.Value + value
				return ("Gave Spins to player."):format(#players)
				end
			end
			local ArtSpins = character:WaitForChild("ArtSpins")
			if ArtSpins.Value ~= "none" then
				local ArtSpin = ArtSpins
				if ArtSpin then
				player.Character.ArtSpins.Value = player.Character.ArtSpins.Value + value
				return ("Gave ArtSpins to player."):format(#players)
				end
			end
		end
	end
end

The first part works correctly, I just need help with the second one in the ArtSpins to apply to the correct value and not the first one.
12

This is how it looks inside the game, and the Spins works correctly not the ArtSpins.

1 Like

From what I can see in your code, if the value of ArtSpins of any specific player is “none”, it wont give that player any more ArtSpins. Is that supposed to be happening?

edit: wait nvm misread

ok I see
See heres the thing: You never check wether the “stat” argument is “Spins” or “ArtSpins”. You just check if the “Spins” value in the player character is “None”, and if not, you give it spins and simply return. Thus, if the player has a “Spins” values (if not, it would error, you should check for its existance BEFORE checking for its value, not after) and that value is not “none”, then no matter if you’re trying to give spins or artspins, the player always gets spins and nothing else.

If the Spins value is none, then the player always gets ArtSpins no matter what.

The following code should work (I hope, because I can’t open studio rn)

return function (_, players, stat: string, value: number, Spins, ArtSpins)
	for _, player in pairs(players) do
		local character = player.Character
		if character then
			if stat == "Spins" then
				local Spins = character:WaitForChild("Spins")
				if Spins then
					if Spins.Value ~= "none" then
						player.Character.Spins.Value += value
						return ("Gave Spins to player."):format(#players)
					end
				end
			else
				local ArtSpins = character:WaitForChild("ArtSpins")
				if ArtSpins then
					if ArtSpins.Value ~= "none" then
						player.Character.ArtSpins.Value += value
						return ("Gave ArtSpins to player."):format(#players)
					end
				end
			end
		end
	end
end
2 Likes

Hello, thanks you, it works, I have another question is about a diferent script, if you are available if not don’t worry, but thanks for the help!

Sure! If you’ve already made a post for it, gimme the link and ill take a look

wait what why delete

charactersaaaaa

Me bad I’m making a post right now.

1 Like

This script is for a clan system, it actually works because when I use the command it shows me the clan list and I can select them, but when I select them I only can get the name of the folder, and not the clan selected.
2

return function (_, players, clanname, clans: string)
	for _, player in pairs(players) do
	local character = player.Character
		if character then
			local Clanfolder = game.ReplicatedStorage:WaitForChild("Clans")
			local ClanValue = character:WaitForChild("Clan")
			if ClanValue then
				if ClanValue.Value ~= "none" then
					local Clans = ClanValue
					if Clans then
						player.Character.Clan.Value = Clanfolder.Name
					end
			end
			end

	return ("Assigned clan to Player."):format(#players)
		end
	end
	end

Nvm lol I can’t make a new post it says is similar to the last one.

1 Like

well you are kinda setting the player.Character.Clan.Value (which is literally Clans, why dont you just do Calns.Value) to Clanfolder.Name, so why won’t it give you the name of the folder?

You should instead be setting it to Clanfolder[clanname], Clanfolder[clanname].Name, or Clanfolder[clanname].Value depending on what part of the objects in the Clans folder you want to get.

1

Here is an example, when I select one of those clans I get the folder name, I want to get the name of the clan selected.

The player.Character.Clan.Value is because “Clan” is a stringvalue, like the one of the spins and artspins before.

Oh I see

Firstly, Clans (or ClanValue, “Clans” is kinda useless lol) is literally just player.Character.Clan, they’re the same thing. Thus, Clans.Value and player.Character.Clan.Value should be the same thing as well.
(Unless its that goofy thing again and I forgot because I haven’t touched studios in months lol)

As for how to not get the folder name, gimme a second to read the cmdr documentation, since im pretty sure thats something related to cmdr itself.

Alright, thanks but here is a proof of what happens.
1

As you see “Clans” is the folder name, I’m trying to get the clan’s name I select with the commands.

ok wait first could you make the script print the “clanname” argument since I want to make sure if its really cmdr’s fault and not because you’re doing Clanfolder.Name

(just put “print(clanname)” right after the return function line)

I still suspect that the issue is that you’re doing Clanfolder.Name rather then Clanfolder[clanname].Name

(also im assuming that the “clanname” argument is what you select)

Yeah I’m trying to get the clan name from a string value inside the folder.

Yes. In that case, you should replace the line player.Character.Clan.Value = Clanfolder.Name with player.Character.Clan.Value = Clanfolder[clanname].Value

Alr Ima try that, also this is what it shows with the print.

what the thats weird

if my solution doesn’t work can you show me where and how you placed the print? (and try printing the clans variable instead. The lowercase one, not the uppercase one)

I got an error invalid argument #2.

Show me the script on how you did it

return function (_, players, clanname, clans: string)
	for _, player in pairs(players) do
	local character = player.Character
		if character then
			local Clanfolder = game.ReplicatedStorage:WaitForChild("Clans")
			local ClanValue = character:WaitForChild("Clan")
			if ClanValue then
				if ClanValue.Value ~= "none" then
					local Clans = ClanValue
					if Clans then
						player.Character.Clan.Value = Clanfolder.Name
					end
			end
			end
			print(clanname)
			return ("Assigned clan to Player."):format(#players)
			
		end
	end
end

12

Here

Copyright? Copyright from who?

1 Like