Error with script

I am trying to make a equip pet button but It’s giving an error
Local script

equipbtn.MouseButton1Click:Connect(function()
	if (selctedTemplate ~= nil) then
		local result = game.ReplicatedStorage.Equip:InvokeServer(selctedTemplate.Name)
		print(result)
		if result == "Equip" then
			script.Parent.Value.Value = script.Parent.Value.Value +1
			equipbtn.Text = "Unequip"
			selctedTemplate:FindFirstChild("Value").Value = true
		else
			script.Parent.Value.Value = script.Parent.Value.Value -1
			equipbtn.Text = "Equip"
			selctedTemplate:FindFirstChild("Value").Value = false
		end
	end
end)

Server Script

local pass = 22995691

game.ReplicatedStorage.Equip.OnServerInvoke = function(player,petName)
	if player.PetInventory:FindFirstChild(petName) then
		if workspace.PlrPets:FindFirstChild(player.Name) then
			if #game.Players:FindFirstChild(player.Name).PlayerGui:WaitForChild("handler").Value.Value <= 5 then
				return "Equip"
			elseif #game.Players:FindFirstChild(player.Name).PlayerGui:WaitForChild("handler").Value.Value == 5 then
				if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, pass) then
					local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName, true)
					if pet ~= nil then
						local cloned = pet:Clone()
						cloned.Parent = workspace.PlrPets:FindFirstChild(player.Name)
					end
					return "Equip"
				else
					return "UnEquip"
				end
			end
		elseif #game.Players:FindFirstChild(player.Name).PlayerGui:WaitForChild("handler").Value.Value > 5 then
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, pass) then
				local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName, true)
				if pet ~= nil then
					local cloned = pet:Clone()
					cloned.Parent = workspace.PlrPets:FindFirstChild(player.Name)
				end
				return "Equip"
			end
		elseif #game.Players:FindFirstChild(player.Name).PlayerGui:WaitForChild("handler").Value.Value == 8 then
			return "UnEquip"
		end
	else
		player:Kick("You have been kicked for exploiting")
	end
end

Error

ServerScriptService.Pet Scripts.Script:6: attempt to get length of a number value

Is this the line erroring?

I see .Value two times at the end there…

.Value.Value
1 Like

Yes that line is the error I think I see the error I will fix it thank you

Wait nevermind It’s not fixed and the reason why value is called twice is because that’s what the object is called
image

I would reframe from naming things after properties of an instance

Ok I wwill change the name of the value

It still gives the same error

ServerScriptService.Pet Scripts.Script:6: attempt to get length of a number value  -  Client - LocalScript:85

this is line 85 in the local script

local result = game.ReplicatedStorage.Equip:InvokeServer(selctedTemplate.Name)

Do you think line 85? is causing the error because it says line 6 is…

Also…
Im curious about this # you place before game what is it supposed to do?

Im not sure when I was making the script my friend told me to put it there and I just did

Could you remove it I have no clue what it would be doing or should be doing ( In this case )

I removed the # it and it works

1 Like

Only use the # when you trying to get the length of a string or table

1 Like